Set Up Multiple Slots in a Lex Chatbot¶
| Category | AWS Chatbots (Amazon Lex) |
| Status | โ Completed |
| Repo | nextwork-set-up-multiple-slots-in-a-lex-chatbot |
| Original NextWork guide | nextwork.ai |
Learning project
Practice work following a NextWork guide, separate from my production projects.
๐ NextWork learning project. This is a practice project I built while working through NextWork's Set Up Multiple Slots in a Lex Chatbot guide. It is part of my Learning portfolio and is fully separate from my production projects.
Category: Learning โบ AWS Chatbots (Amazon Lex)
Status: โ
Completed
Overview¶
The final build part: BankerBot moves money. TransferFunds collects three slots (two reuse the accountType slot type, one is AMAZON.Number), asks the user to confirm before acting, handles 'no', and the Lambda rejects transfers between the same account.
Summary¶
On real Lex V2 + Lambda, TransferFunds collected 3 slots (source account, target account and amount), asked the confirmation prompt, and completed the transfer on "yes" or answered "The transfer has been cancelled" on "no". Context carry-over (FollowupCheckBalance reusing the verified date of birth) also worked. Deleted afterwards.
The checks behind this are in docs/verification.txt.
Skills & tools¶
Amazon Lex V2, Conversational AI, Intents & utterances, NLU, Python, pytest, Terraform, Multi-slot intents, Confirmation prompts, Input validation
What I built¶
bot/bankerbot.json: TransferFunds (utterances with all three slots inline, prompts, confirmation and declination responses).lambda/lambda_function.py:transfer_fundswith a same-account validation.tests/test_part5.py: step-by-step elicitation, the all-in-one utterance, decline, and the validation failure.
How to run¶
pip install pytest
pytest -q tests # scripted conversations against the bot definition + Lambda
python3 chat.py # chat with BankerBot locally
terraform init && terraform validate # real Lex V2 resources (apply needs an AWS account)
Verification¶
I ran the verification command on 2026-12-03. The full output is in docs/verification.txt.
PATH=/workspace/nextwork-portfolio/.venv/bin:$PATH python -m pytest -q -p no:cacheprovider tests && printf 'Hello\nCheck my account balance\n1990-04-21\nsavings\n' | /workspace/nextwork-portfolio/.venv/bin/python chat.py && TF_PLUGIN_CACHE_DIR=/workspace/nextwork-portfolio/tf-plugin-cache terraform init -backend=false -input=false >/dev/null && terraform validate -no-color; rc=$?; rm -rf .terraform .terraform.lock.hcl .build; exit $rc
Real AWS deployment (2026-12-02)¶
Note:
docs/aws-real-run.txtis the log of the original real-AWS run, so its fallback reply is the bot's wording at that time. The bot definition has since been reworded in my own words.
I deployed this project to a real, dedicated AWS learning account (us-east-1, kept separate from everything else I run), checked it, captured the output, and tore it all down right after. Every resource carried the tag Project=nextwork-set-up-multiple-slots-in-a-lex-chatbot so I could prove nothing was left behind.
How I ran it: python3 real-aws-run.py . real-conversation.txt (in this repo) reads bot/bankerbot.json and creates the real Lex V2 bot through the AWS API: IAM role, bot, en_US locale, slot types, intents, slots and contexts, plus the fulfillment Lambda where the guide has one. It builds the locale, holds the scripted conversation through the Lex runtime (RecognizeText on the TestBotAlias), and then always deletes everything, even if a step fails. (The lex.tf here is a partial Terraform sketch. I used the API script because it builds the complete bot from the same JSON the local simulator uses.)
Evidence (excerpt; the full, sanitized transcript is in docs/aws-real-run.txt, with the account ID redacted):
[21:41:27] created IAM role NW-LexRole-9f55ba (Lex runtime role)
[21:41:41] created Lambda BankingBotEnglish-9f55ba (python3.12) from lambda/lambda_function.py
[21:41:52] created Lex V2 bot BankerBot-9f55ba (U3ANG7CVJE)
slot type accountType: 3 values
intent WelcomeIntent: 7 utterances, slots=[]
intent FallbackIntent: custom closing response
intent CheckBalance: 7 utterances, slots=['dateOfBirth', 'accountType'], Lambda fulfillment, contexts in=None out=['contextCheckBalance']
intent FollowupCheckBalance: 3 utterances, slots=['accountType', 'dateOfBirth'], Lambda fulfillment, contexts in=['contextCheckBalance'] out=[]
intent TransferFunds: 6 utterances, slots=['sourceAccountType', 'targetAccountType', 'transferAmount'], Lambda fulfillment, confirmation prompt
[21:41:59] building locale en_US ...
[21:42:39] locale built
[21:42:40] TestBotAlias now calls the Lambda for fulfillment
=== Conversation with the REAL bot (lexv2-runtime recognize-text, TestBotAlias) ===
--- new session
you> Hello
bot> Hi! I'm BB, the Banking Bot. How can I help you today? [intent=WelcomeIntent state=Fulfilled]
--- new session
you> Check my account balance
bot> For verification purposes, what is your date of birth? [intent=CheckBalance state=InProgress]
you> 1990-04-21
bot> What type of account would you like to check? [intent=CheckBalance state=InProgress]
you> checking
bot> Thank you. The balance on your Checking account is $3,858.11 dollars. [intent=CheckBalance state=Fulfilled]
you> How about my savings account?
bot> Thank you. The balance on your Savings account is $1,125.69 dollars. [intent=FollowupCheckBalance state=Fulfilled]
--- new session
you> I want to transfer funds
bot> Which account would you like to transfer from? [intent=TransferFunds state=InProgress]
you> checking
bot> Which account are you transferring to? [intent=TransferFunds state=InProgress]
you> savings
bot> How much money would you like to transfer? [intent=TransferFunds state=InProgress]
you> 250
bot> Got it. So we are transferring $250 from Checking to Savings. Can I go ahead with the transfer? [intent=TransferFunds state=InProgress]
you> yes
bot> The transfer of $250.00 from your Checking account to your Savings account is complete. [intent=TransferFunds state=Fulfilled]
--- new session
you> I want to transfer funds
bot> Which account would you like to transfer from? [intent=TransferFunds state=InProgress]
you> savings
bot> Which account are you transferring to? [intent=TransferFunds state=InProgress]
you> credit card
bot> How much money would you like to transfer? [intent=TransferFunds state=InProgress]
you> 40
bot> Got it. So we are transferring $40 from Savings to Credit. Can I go ahead with the transfer? [intent=TransferFunds state=InProgress]
you> no
bot> The transfer has been cancelled. [intent=TransferFunds state=Failed]
--- new session
you> what is the weather on Mars
bot> [fallback reply in the bot's original wording at the time; see docs/aws-real-run.txt] [intent=FallbackIntent state=Fulfilled]
Teardown¶
Resources were up from 21:41 to 21:42 CST on 2026-12-02, then destroyed and verified gone:
=== TEARDOWN 21:42:52 ===
deleted Lex bot U3ANG7CVJE
deleted Lambda BankingBotEnglish-9f55ba
deleted its CloudWatch log group
deleted IAM role NW-LexFnRole-9f55ba
deleted IAM role NW-LexRole-9f55ba
bots left in account: none
lambdas left: none
=== teardown verified 21:42:56 ===
Cost¶
Estimated cost of the real run: about $0.02 across two runs (a handful of Lex text requests and Lambda invocations; my first run failed at the locale build because Lex needs a space between a {slot} and a following ?, then everything was deleted and re-run). The account has a $50/month budget with email alerts at $5, $20 and $40, and the whole AWS series is logged in a private spend ledger.
Original project: https://nextwork.ai/projects/13cfd692-9802-5c98-ada7-92fde8b30a99 ยท Part of my NextWork Learning portfolio (hub).
Verification output¶
From docs/verification.txt:
$ PATH=/workspace/nextwork-portfolio/.venv/bin:$PATH python -m pytest -q -p no:cacheprovider tests && printf 'Hello\nCheck my account balance\n1990-04-21\nsavings\n' | /workspace/nextwork-portfolio/.venv/bin/python chat.py && TF_PLUGIN_CACHE_DIR=/workspace/nextwork-portfolio/tf-plugin-cache terraform init -backend=false -input=false >/dev/null && terraform validate -no-color; rc=$?; rm -rf .terraform .terraform.lock.hcl .build; exit $rc
............. [100%]
13 passed in 0.02s
BankerBot (type 'quit' to exit)
you> Hello
bot> Hello! BankerBot here. Ask me about your account balance or a transfer.
you> Check my account balance
bot> For verification purposes, what is your date of birth?
you> 1990-04-21
bot> What type of account would you like to check?
you> savings
bot> Thank you. The balance on your Savings account is $1,133.66 dollars.
Success! The configuration is valid.
[exit code 0]