How to Build a Native Chatbot With Amazon Lex in Under Two Hours


Building a native chatbot doesn’t have to be a complicated, multi-week project. With Amazon Lex and other parts of the AWS ecosystem, you can build a conversational bot on a standalone framework in just a couple of hours. 

Chatbots are quickly becoming a ubiquitous part of the e-commerce landscape and spilling over into other parts of business and technology. In simple terms, if you’re not investing in chatbots, you’re missing out. According to the Salesforce State of the Connected Customer report: 

  • 86% of customers would rather talk to a chatbot to get answers than fill out a form 
  • 77% of customers expect chatbots to change their expectations of companies in the next 5 years
  • 58% of customers say they have higher expectations of companies in light of emerging tech like chatbots and voice assistants 
  • 54% of customers expect businesses to transform their interactions with them 

There’s one major advantage with chatbots over other routes of communication: They’re always on and never need staffing. It’s easy to lose a customer who’s frustrated because your CS phone line’s hours don’t align with their availability, or a customer who’s been on hold for too long because there isn’t an available agent. Chatbots eliminate that risk.

Plus, chatbots are fast, which is another massive draw. The Salesforce report says customers expect the same response time from face-to-face conversations and chatbots alike, and they expect chatbots to be even faster than an agent on the phone. In most cases, a well-designed bot can deliver on that expectation. 

Building a native chatbot can be costly and resource-intensive without a reliable framework in place. For users of Amazon Web Services, Amazon Lex is a framework that offers flexible and sophisticated bot-crafting tools and connects to the AWS network of integrations and services. 

This agile framework can build text- and voice-based chatbots using the same intelligent backend technology that fuels natural conversational speech recognition in Amazon Alexa. 

An Amazon Lex use case for every kind of chatbot 

Chatbots are popular in e-commerce and customer service, but those are far from the only applications where Amazon Lex can come in handy. The framework allows users to build:

  • A chatbot that forecasts the weather: With Lex, you can use AWS Lambda to build a Slack bot that returns weather conditions in response to a query like “Show me the weather in my city.” 
  • A chatbot that automates searches: Lex can be used to aggregate and retrieve data based on specific parameters, freeing up analysts to work on higher-priority tasks. 
  • A chatbot that develops apps by voice control: You can use Lex to build a voice assistant bot that lets non-dev users code apps without having to actually write any code. Instead, the bot can respond to voice commands to insert functions. 

These are the technologies that stack well for chatbot creation

You should already be an Amazon Web Services user to take advantage of Amazon Lex. When you’re working with the framework, consider using other services within the AWS ecosystem, such as: 

  • Amazon Connect: Connect is an omnichannel cloud contact center solution that scales at low cost and enables dynamic customer-agent interactions. You can route all your customer communications here, including chatbot conversations.  
  • Amazon Polly: Users of Amazon Polly can automate text-to-speech synthesizing and let you build speech-enabled chatbot apps that act as voice assistants, take commands, or answer questions. 
  • Amazon Chatbot: AWS Chatbot lets you monitor your Slack and Amazon Chime chat rooms for alerts, diagnostics, support cases, and more. It’s an easy way to keep everyone on your team in the loop while you’re integrating the native chatbot and troubleshooting during the early rollout days. 
  • AWS Lambda: This service is an admin-free platform for running code without server management. It’s an affordable way to execute your chatbot app since you’re only charged per 100ms of code execution or computing time you actually use. 
  • Amazon Simple Notification Service: A versatile chatbot should support system-to-system communication tool (and app-to-person if you integrate your chatbot into an app). Amazon SNS lets you send messages at scale via SMS or mobile push to millions of users.

Creating a native chatbot in under two hours

With Amazon Lex and other services from the AWS ecosystem, it’s possible to create a native chatbot in under two hours with only minor development experience. (Business owners with no dev experience whatsoever may want to outsource this part.) 

In six steps, here’s how to build a native chatbot in Lex: 

1. Create a custom Lex bot

Log in to AWS and navigate to Lex. Click “Get Started” and set up the service, then click “Create” and select “Custom Bot.”While creating your custom bot, fill in the name and output voice, or choose “This is only a text-based app.” Enter one minute for the “Session Timeout” field and choose “No” for “COPPA.” Then, click “Create.” 

2. Assign an intent
Click “Create intent” and then “Create new intent.” Let’s say you want to make your bot list recent orders when your customers prompt it. Name the intent “ListRecentOrders.” 

Under “Sample Utterances,” enter variations of phrases that a user could say when trying to retrieve their recent orders. They may include: 

  • List my orders
  • List recent orders
  • Show orders 
  • Show recent orders

To actually retrieve those recent orders, you’ll need to have Amazon Connect setup with a database of customer data, including purchasing history. (We’ll cover that one another day!) 

3. Generate a Lambda function

Go to the IAM console and choose “Roles,” then “Create role,” and then “Lambda.” Click “Next: Permissions” and type “Lambda basic” in the search bar. 

Choose the permission “AWSLambdaBasicExecutionRole.” Name it “basic-lambda-execution” and choose “Create role.” 

From Lambda, click “Create function,” “Author from scratch,” and then type “BotHandler” as the function name. Choose the role from IAM and pick “Create function.” 

4. Build and test the bot

Go back to Lex Console and select the bot you created in the first step. Select the intent and then scroll to “Fulfillment” and choose “AWS Lambda Function.” Then, choose “BotHandler,” the function from step 3. 

Click “Build” and then test it out by opening the chatbot and typing one of the sample utterances that you used in step 2. 

5. Set up Amazon Cognito

Amazon Cognito can give your native app permission to talk to mobile apps and other outside sources. Open Cognitio Console and click on “Manage Federated Identities,” then “Create New Identity Pool.” Name the pool “LexBotPool” and choose “Enable access to unauthenticated identities” before creating the pool. 

Leave all the settings default and click “Allow.” On the next page, change the environment to Javascript and copy the sample code for adding the bot to your native app later.

Then, go to the IAM console, choose “Roles” and attach the policies “AmazonPollyReadOnlyAccess” and “AmazonLexRunBotsOnly” to the Cognito roles from earlier.  

Apart from adding the bot to a native app, that’s the entire process! Now you have a working chatbot that has a specific function. That’s only one of many ways to build a chatbot in Amazon Lex, but the possibilities are endless thanks to the framework’s flexibility and the ecosystem’s vast number of AWS tools and services. 

CloudHesive can help manage your Amazon Connect services and more 

Need the expertise of an Amazon Premier Partner and Managed Services Partner? CloudHesive can guide your cloud strategy, including native chatbot deployment and much more. We’ll help you improve productivity and operating costs while maximizing security and providing you the expertise you need to increase your global capacity. Reach out today to learn how CloudHesive can partner with you to help!

Related Blogs

  • Amazon Personalize: Create a Customer Experience Worthy of Brand Loyalty

    Get the contact center analytics you need to offer a hyper-personalized experience Key Takeaways: Customers have many options. Why should they choose you? Amazon Personalize gives them the experience...

    Learn More
  • Your Complete Guide to Leveraging AWS Connect Integrations for Call Center Success

    Integrate data and evolve your contact center Key Takeaways: Today’s SaaS call centers are powered by integrated data and applications. Customers expect hyper-personalization – give your agents...

    Learn More
  • Exploring the Role of Amazon Web Services (AWS) Tools for DevOps Implementation in Cloud Projects

    Integrating DevOps best practices into cloud projects presents a few inherent challenges. With the help of AWS Tools for DevOps, processes can be streamlined for better cloud project management....

    Learn More