Amazon Lex
Hands-On
Demo

In this demo, we will:
- Create a Lex bot for pizza ordering
- Define intents and configure slot types
- Add sample utterances and train the bot
- Create a Lambda function for order processing
- Configure bot fulfillment with Lambda
- Test the conversational flow
- Clean up resources
Agenda

Create bot

Configure bot settings

PizzaOrderBotBot configuration
A bot to take pizza orders
IAM permissions

Bot error logging

Children's Online Privacy Protection Act (COPPA)

Idle session timeout

Advanced settings - optional

Add language to bot

Slots

Add slot type

Add blank slot type

PizzaSizeAdd blank slot type

Slot type details
PizzaSizeAvailable pizza sizes
Slot value resolution

smallmediumlargeSlot type values

Add a 2nd blank slot type

PizzaTypeAdd blank slot type

Available pizza typesSlot type details

Slot type values
margheritapepperonivegetarianhawaiian
Add intent

Add empty intent

Add empty intent
OrderPizza
Intent to order a pizzaIntent details

Contexts - optional

I want to order a pizza
I'd like a {PizzaSize} {PizzaType} pizza
Can I get a {PizzaType} pizza
I want a {PizzaSize} pizza
Order a {PizzaType} pizza please
I'd like to order a {PizzaSize} {PizzaType}
Get me a pizza
Pizza order
Can I order a {PizzaType}
I need a {PizzaSize} {PizzaType} pizzaSample utterances

Add slot

What type of pizza would you like?PizzaTypeAdd slot

Add slot
PizzaSizeWhat size would you like?
Add slot
QuantityHow many pizzas would you like?
Slots

Confirmation
You want to order {Quantity} {PizzaSize} {PizzaType} pizza(s). Is that correct?Okay, let's start over. What would you like to order?
Fulfillment & Closing response

Save intent

Create Lambda function
PizzaOrderProcessor
Permissions

Additional configurations

import json
import random
import string
def lambda_handler(event, context):
# Extract intent name
intent_name = event['sessionState']['intent']['name']
# Extract slot values
slots = event['sessionState']['intent']['slots']
if intent_name == 'OrderPizza':
pizza_type = slots['PizzaType']['value']['interpretedValue']
pizza_size = slots['PizzaSize']['value']['interpretedValue']
quantity = slots['Quantity']['value']['interpretedValue']
# Generate order number
order_number = ''.join(random.choices(string.ascii_uppercase + string.digits, k=8))
# Calculate price (simplified pricing)
size_prices = {'small': 10, 'medium': 15, 'large': 20}
base_price = size_prices.get(pizza_size, 15)
total_price = base_price * int(quantity)
# Prepare fulfillment message
fulfillment_message = (
f"Great! Your order has been placed. "
f"Order #{order_number}: {quantity} {pizza_size} {pizza_type} pizza(s). "
f"Total: ${total_price}. "
f"Your order will be ready in 30-40 minutes."
)
response = {
"sessionState": {
"dialogAction": {
"type": "Close"
},
"intent": {
"name": intent_name,
"state": "Fulfilled"
}
},
"messages": [
{
"contentType": "PlainText",
"content": fulfillment_message
}
]
}
else:
response = {
"sessionState": {
"dialogAction": {
"type": "Close"
},
"intent": {
"name": intent_name,
"state": "Failed"
}
},
"messages": [
{
"contentType": "PlainText",
"content": "Sorry, I couldn't process your request."
}
]
}
return response
TestBotAlias

Alias: TestBotAlias

Languages

Add Lambda function

Go to Intents

Fulfillment

Fulfillment Lambda code hook

Build the Intent

Successfully built language English (US) in bot: PizzaOrderBot

I want to order large pepperoni
pizzas2
yes
1 more test run
I want to order a pizzaVegetarianMedium
1Yes
YesClean Up

Delete Lambda function

Delete Bot

Delete bot PizzaOrderBot?

Delete Lambda Execution Role
Pizza
Delete PizzaOrderProcessor-role-Oacc4y6z?

Delete Lex IAM Service Role
Lex
Delete Lex IAM Service Role
🙏
Thanks
for
Watching
Amazon Lex - Hands-On Demo
By Deepak Dubey
Amazon Lex - Hands-On Demo
Amazon Lex - Hands-On Demo
- 133