Building Conversational Chatbots with Amazon Lex - Intent Design and Lambda Integration

Define intents and slots with a natural language understanding (NLU) engine and execute backend processing through Lambda integration to build interactive bots. This article covers multilingual support and streaming conversation API usage.

Overview of Lex

Amazon Lex is a service for building conversational interfaces that combines natural language understanding (NLU) with automatic speech recognition (ASR). Built on the same deep learning technology as Alexa, it enables building interactive bots for both text and voice. The current Lex V2 is significantly enhanced over V1, offering multi-language support, streaming conversation APIs, and improved slot resolution logic. It can be applied to any use case requiring natural language interaction with users, including chatbots, IVR (Interactive Voice Response), and customer support automation.

Designing Intents and Slots

A Lex bot is composed of intents (user intentions) and slots (parameters). For example, a "hotel booking bot" would define a BookHotel intent with CheckInDate, Nights, and RoomType slots. Sample utterances are registered for each intent ("I'd like to book for 2 nights starting next Friday," "Book a single room"), and the NLU engine maps user input to intents. Slot types use a mix of built-in types (AMAZON.Date, AMAZON.Number, AMAZON.City) and custom types. Confirmation prompts verify slot values with the user, and fulfillment calls a Lambda function to execute backend processing (calling a booking API, writing to a database). Use the test window to debug conversation flows and check intent recognition accuracy and slot resolution status in real time.

Lambda Integration and External Connections

Lex provides two types of Lambda integration: dialog code hooks and fulfillment code hooks. Dialog code hooks are called at each turn and used for slot value validation and dynamic prompt generation. Fulfillment code hooks are called after all slots are filled and execute actual business logic (booking processing, order confirmation). Integration with Amazon Connect embeds Lex bots into contact center IVR for automated phone responses. Integration with external channels like Twilio and Facebook Messenger is also possible via API. Integration with Kendra provides the ability to automatically search FAQ documents for answers. For conversational AI design patterns, related books on Amazon are also a helpful reference.

Lex Pricing

Lex V2 pricing is pay-per-use based on request count. Text requests cost approximately $0.75 per 1,000 requests, and voice requests cost approximately $4.00 per 1,000 requests. The streaming conversation API charges based on audio duration at approximately $0.0002 per second. The free tier includes 10,000 text requests/month and 5,000 voice requests/month for the first 12 months. When used with Connect integration, Connect call charges apply in addition to Lex pricing.

Summary

Amazon Lex is a conversational bot building service powered by the same NLU/ASR technology as Alexa. Define conversation flows through intent and slot design, and execute backend processing through Lambda integration. Build conversational interfaces across diverse channels and services, including voice bots with Connect integration and automated FAQ responses with Kendra integration.