Build a Chatbot with Amazon Lex¶
| Category | AWS Chatbots (Amazon Lex) |
| Status | โ Completed |
| Repo | nextwork-build-a-chatbot-with-amazon-lex |
| 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 Build a Chatbot with Amazon Lex 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 1 of the Lex series. You create BankerBot, a WelcomeIntent trained on greeting utterances, and a FallbackIntent for anything the bot doesn't understand. Responses use message groups with variations so the bot doesn't sound robotic.
Summary¶
Built BankerBot on real Amazon Lex V2 (WelcomeIntent with 7 utterances and rotating replies, plus a custom FallbackIntent) and chatted with it through the Lex runtime: greetings went to WelcomeIntent and "what is the weather on Mars" went to FallbackIntent. The bot and its role were deleted afterwards.
The checks behind this are in docs/verification.txt.
Skills & tools¶
Amazon Lex V2, Conversational AI, Intents & utterances, NLU, Python, pytest, Terraform
What I built¶
bot/bankerbot.json: bot definition (locale, idle timeout, a 0.40 confidence threshold, WelcomeIntent, and FallbackIntent with variations).simulator/lexsim.py: the local Lex V2-style runtime (shared across the series).tests/test_part1.py: greeting variations, fuzzy matching, and fallback.lex.tf:aws_lexv2models_bot, bot locale, and WelcomeIntent.
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\ngood morning\nhey there\nwhat is the weather on mars\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-build-a-chatbot-with-amazon-lex 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:04:22] created IAM role NW-LexRole-f777ee (Lex runtime role)
[21:04:33] created Lex V2 bot BankerBot-f777ee (YUXSTOVFXD)
intent WelcomeIntent: 7 utterances, slots=[]
intent FallbackIntent: custom closing response
[21:04:37] building locale en_US ...
[21:05:02] locale built
=== 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> Hi BankerBot
bot> Hi! I'm BB, the Banking Bot. How can I help you today? [intent=WelcomeIntent state=Fulfilled]
--- new session
you> Can you help me?
bot> Hey there, I'm BankerBot! I can check your balance or move money. What do you need? [intent=WelcomeIntent state=Fulfilled]
--- 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:04 to 21:05 CST on 2026-12-02, then destroyed and verified gone:
=== TEARDOWN 21:05:04 ===
deleted Lex bot YUXSTOVFXD
deleted IAM role NW-LexRole-f777ee
bots left in account: none
lambdas left: none
=== teardown verified 21:05:07 ===
Cost¶
Estimated cost of the real run: about $0.01 (a handful of Lex text requests; building and storing a bot is free). 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/143bcc99-ef5a-58e7-96f0-45d7c00b761a ยท 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\ngood morning\nhey there\nwhat is the weather on mars\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%]
3 passed in 0.01s
BankerBot (type 'quit' to exit)
you> Hello
bot> Hi! I'm BB, the Banking Bot. How can I help you today?
you> good morning
bot> Hey there, I'm BankerBot! I can check your balance or move money. What do you need?
you> hey there
bot> Hi! I'm BB, the Banking Bot. How can I help you today?
you> what is the weather on mars
bot> Sorry, I didn't follow that. You can ask me for your balance, to move money between your accounts, or to pay a bill.
Success! The configuration is valid.
[exit code 0]