Add Custom Slots to a Lex Chatbot¶
| Category | AWS Chatbots (Amazon Lex) |
| Status | โ Completed |
| Repo | nextwork-add-custom-slots-to-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 Add Custom Slots to 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¶
Part 2 teaches BankerBot to check balances. A custom slot type accountType (Checking, Savings, Credit, plus synonyms like 'visa') and a built-in AMAZON.Date slot for the date of birth feed a new CheckBalance intent. Sample utterances can carry slots inline (Balance in {accountType}). For the secret mission, the bot handles errors with retry prompts and a failure response.
Summary¶
Built BankerBot on real Amazon Lex V2 with the custom accountType slot type (Checking, Savings and Credit, with synonyms) and the CheckBalance intent, which asks for dateOfBirth (AMAZON.Date) and accountType. Real conversations filled both slots, resolved "visa" to Credit from the utterance itself, parsed "April 21 1990" as a date, and reached FallbackIntent for off-topic input. Deleted afterwards.
The checks behind this are in docs/verification.txt.
Skills & tools¶
Amazon Lex V2, Conversational AI, Intents & utterances, NLU, Python, pytest, Terraform, Slots & slot types, Slot elicitation, Error handling
What I built¶
bot/bankerbot.json: adds theaccountTypeslot type (TopResolution with synonyms) and CheckBalance (utterances, prompts, retries, failure response).tests/test_part2.py: elicitation order, inline slot plus synonym resolution, and retry then 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-add-custom-slots-to-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:39:18] created IAM role NW-LexRole-f1fe30 (Lex runtime role)
[21:39:29] created Lex V2 bot BankerBot-f1fe30 (1B3HLZXVFM)
slot type accountType: 3 values
intent WelcomeIntent: 7 utterances, slots=[]
intent FallbackIntent: custom closing response
intent CheckBalance: 7 utterances, slots=['dateOfBirth', 'accountType']
[21:39:34] building locale en_US ...
[21:40:02] locale built
=== Conversation with the REAL bot (lexv2-runtime recognize-text, TestBotAlias) ===
--- new session
you> Hi
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> savings
bot> Intent CheckBalance fulfilled [intent=CheckBalance state=Fulfilled]
--- new session
you> What is the balance in my visa account?
bot> For verification purposes, what is your date of birth? [intent=CheckBalance state=InProgress]
you> April 21 1990
bot> Intent CheckBalance fulfilled [intent=CheckBalance state=Fulfilled]
--- new session
you> what is the weather on Mars
bot> Hmm, I didn't catch that. Try something like 'check my balance' or 'transfer money'. [intent=FallbackIntent state=Fulfilled]
Teardown¶
Resources were up from 21:39 to 21:40 CST on 2026-12-02, then destroyed and verified gone:
=== TEARDOWN 21:40:05 ===
deleted Lex bot 1B3HLZXVFM
deleted IAM role NW-LexRole-f1fe30
bots left in account: none
lambdas left: none
=== teardown verified 21:40:08 ===
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/9b23ef35-9a36-5a21-9a3c-cfa3d61a0e2b ยท 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%]
6 passed in 0.01s
BankerBot (type 'quit' to exit)
you> Hello
bot> Hey there, I'm BankerBot! I can check your balance or move money. What do you need?
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> Intent CheckBalance fulfilled
Success! The configuration is valid.
[exit code 0]