Create a BankingBot with English and Spanish support in the Amazon Lex V2 console
TUTORIAL
Create the Bot
You will learn how to create the bot.
Overview
In this module, we’ll create the bot for your banking application (BankingBot), add language support for both English (US) and Spanish (US), then create the fulfillment Lambda function. The bot requires a Lambda function per language as the fulfillment mechanism for its intents.
Time to complete
30 minutes
Implementation
Step 1: Sign in to your AWS Account
Open a browser and navigate to the AWS Management Console located
https://signin.console.aws.amazon.com/
Once logged in, you will arrive at the AWS Management Console Home. Ensure you have selected your desired region based on your infrastructure requirements in the upper right hand corner. Amazon Lex V2 supported regions can be found in the Amazon Web Services General Reference. If using an organizational account ensure you have sufficient permissions. Remember to delete the provisioned resources after finishing this tutorial to avoid unnecessary charges.
Pro Tip: You can learn about the console through the Getting Started with AWS Management Console tutorial.
Step 2: Create a Bot
Sign in to the Amazon Lex V2 console and choose Bots. Then choose Create bot.
Note: If you are using the Lex V1 console, in the left navigation menu choose Switch to the new Lex V2 console.
On the Configure bot settings page, for Creation method, choose Create a blank bot.
In the Bot configuration section, for Bot name, type BankingBot and type an optional description.
In the IAM Permissions section, for Runtime role, choose Create a role with basic Amazon Lex permissions.
In the Children's Online Privacy Protection Act (COPPA) section, choose No as it is only for demo purposes.
Leave the remaining settings as their default values and choose Next.
In Select Language choose English(US), leave the other settings as their default then choose Add another language.
In Select Language choose Spanish (US), leave the other default settings and select Done.
A NewIntent will be created for you. We’ll configure the Intents in the next Module but first we need to create the Lambda functions for intent fulfillment.
Step 3: Create the Lambda functions
Instead of one Lambda function for each intent, Amazon Lex V2 uses a Lambda function per bot alias and language. The Lambda function router section then provides a function that you can use to direct a request to an individual function. For the BankingBot we require two Lambda functions.
Sign in to the AWS Lambda console and choose Functions. Then, choose Create function.
On the Create function page, choose Author from scratch. For Basic information, specify the following details:
- For Function name, type BankingBotEnglish (for the English version) or BankingBotSpanish (for the Spanish version).
- For Runtime, choose Python 3.9.
Select Create function.
In the Code source section, open lambda_function.py and delete the existing code. Download the BankingBotEnglish or BankingBotSpanish Lambda code and open it in a text editor. Copy and paste the code into the empty lambda_function.py tab. Then, press Deploy.
Since we need to create a separate Lambda function for each language, repeat Step 3 to add and deploy the second one (English or Spanish).
Step 4: Add the Lambda function to your bot
Now that you have created the Lambda functions, you need to connect your bot to them. These functions act as fulfillment mechanisms for the bots intents.
Sign in to the Amazon Lex V2 console and in the left navigation pane, navigate to BankingBot > Deployment > Aliases. Then, choose TestBotAlias.
On the Aliases: TestBotAlias page, in the Languages section, choose English (US) or Spanish (US) depending on which fulfillment Lambda function you are creating.
On the Alias language support page, make the following selections:
- For Source, choose BankingBotEnglish or BankingBotSpanish depending on which language you are configuring.
- For Lambda function version or alias, choose $LATEST.
- Click Save
Repeat Step 4 to add Lambda support for each language.
Conclusion
In this module we created the BankingBot, added support for both English (US) and Spanish (US) before creating the Lambda functions to use as the fulfillment mechanism of the intents.
In the next module we’ll add the intents and slots to the English (US) language.