Building Bots with Amazon Lex
Amazon Lex is a flexible chatbot framework with NLU and machine learning capabilities. With Amazon Lex, you can build everything from simple bots for messaging apps to complex bots for enterprise environments. Explore the integrations, SDKs, and unique AWS services available when you build your bot with Amazon Lex.
April 16, 2019
If you’re looking for a versatile chatbot framework with sophisticated bot-building tools, Amazon Lex is a great place to start. With Amazon Lex, you can build anything from consumer-facing virtual assistants to enterprise bots that retrieve information from massive databases. It’s flexible enough for almost anything.
To paint a complete picture of everything you can accomplish, let’s take a comprehensive look at its features, capabilities, and advantages in this Amazon Lex chatbot tutorial. In addition to the framework’s pros, we’ll consider some potential cons, so you know just what to expect.
What is Amazon Lex?
Amazon Lex is a bot-building framework that’s part of Amazon Web Services, or AWS. In the greater context of chatbot frameworks, Amazon Lex is one of the most powerful, capable, multifaceted options available to developers.
When you use Amazon Lex, you’re not confined by your bot’s preprogrammed responses or a graphical user interface (GUI) geared to non-coders (although the Amazon Lex console does provide a GUI for building your bot). Instead, you get the works. The framework comes with built-in natural language understanding (NLU) capabilities and machine learning from AWS. These features help your bot to accurately interpret user intent and to become smarter and more capable as it ages.
In fact, it’s these AWS-powered tools that make Amazon Lex a standout framework that can grow along with your organization. Today, you might need to build a Facebook Messenger chatbot capable of answering 15 specific customer service questions. But, next year, you might need that same bot to answer hundreds of different queries asked in various ways by multiple customers. And you might need it to live on other platforms besides Facebook Messenger.
Not all frameworks can scale to meet those future objectives, but Amazon Lex can.
Amazon Lex also allows you to build text- and voice-based chatbots. It utilizes the same backend technologies and services that power Alexa, so you can build a conversational bot that listens to users when spoken to, speaks back to them, and converts their words to text via automatic speech recognition (ASR).
Amazon Lex chatbot examples
You can build any kind of chatbot with Amazon Lex. From informational and transactional bots that interact with customers to productivity bots built for enterprise work environments, there really aren’t any limitations.
Let’s start with a simple example. One group of developers used the framework to build a chatbot that provides weather forecasts for a given location, and they deployed it on Slack. Using the Amazon Lex GUI, they first defined the bot’s fundamentals. And they used AWS Lambda, the Amazon serverless compute service, to run the backend code. Finally, they launched the bot on Slack using Amazon Lex platform integration tools.
Users can type things like, “Show me the weather in London.” The bot responds with temperature, wind speed, and other conditions for London. It’s a straightforward, useful bot—the kind we’ve all encountered.
Now consider a more sophisticated example: Infor's Coleman chatbot. Coleman mines enormous quantities of data to improve business processes handled through Infor CloudSuite applications. Its purpose? Automate “search and gather” functions so that users can spend more time on high-value, non-administrative activities.
App development - without coding
Another helpful Amazon Lex-built bot is TIBCO’s voice assistant. The bot helps TIBCO’s non-developer users, such as small business owners, work on their own apps without having to write code. Since the bot responds to voice commands, users can actually create apps while driving or enjoying a cup of coffee on a park bench.
Why use Amazon Lex? The pros and cons
Compared to other frameworks, Amazon Lex offers several advantages. When deciding whether Amazon Lex makes sense for your bot development project, consider some of the biggest pros and cons:
First, the good stuff. We’ve already talked about the Amazon Lex NLU and machine learning capabilities. If you’re building anything other than a bot that responds to a pre-programmed list of commands, those features are essential. Additional advantages include straightforward integration with several popular platforms (more on those in a bit) and the overall easiness of getting started. It’s actually free to start building a bot with Amazon Lex. All you need is an AWS account and some time to work on your bot—the barrier to entry is extremely modest!
Now for the cons. It might not make sense to use Amazon Lex if you’re already entrenched in another company’s technologies. For instance, if your company already uses Microsoft Azure Cognitive Services for proprietary software or in particular business units, it might make more sense to piggyback off that and build your bot with the Microsoft Bot Framework. Of course, this isn’t necessarily a con—more like an internal stumbling block that makes using Amazon Lex a bit less convenient.
However, for some developers, the primary disadvantage to Amazon Lex is language—not programming languages (as you’ll see, the framework supports several), but human language. As of early 2019, Amazon Lex is only available in American English. At least for the time being, if you need your bot to speak anything other than English, you’ll have to look elsewhere.
Key features and integrations
After building your bot with Amazon Lex, you can deploy it virtually anywhere. The best part? The AWS learning blog will tell you how. For example, the AWS tutorial for deploying a Web UI for your bot simplifies the process of launching your bot on an existing domain.
Additionally, the Amazon Lex console makes it especially easy to deploy your bot to the following platforms:
- Facebook Messenger
- Twilio SMS
These are the platforms that Amazon Lex supports with integrated deployment features. If, for instance, you want to reach users on Facebook Messenger and Slack, these features can accelerate and streamline deployment on those platforms.
With that said, even if your bot’s primary audience is on a messaging app, it’s always a good idea to also launch your bot on its own domain. That way, your bot can maintain a permanent home, even if you switch to a new framework and/or platform. To make this process even easier, Amazon developed its very own top-level domain specifically for bots. The company’s .BOT domain is a great place to deploy your bot in conjunction with other platforms where your audience is active.
Another useful Amazon Lex feature is its complete AWS integration. Whether you use AWS Lambda for running code or AWS Mobile Hub to add NLU to your mobile app or Route 53 for your DNS, all AWS services are at your fingertips. If you’re already using AWS for other business operations, you might be able to accelerate development by choosing Amazon Lex over other frameworks.
Additional Amazon Lex features include multi-turn conversations, in which the bot prompts users for additional information to fulfill an intent. AWS literature on Amazon Lex uses the example of a user who says, “I need to book a hotel.” The bot would then know to ask about the user’s location, check-in date, and more. Intent chaining capabilities in Amazon Lex help your bot anticipate additional intents beyond what the user has stated. Someone booking a hotel might also need to reserve a car, for instance, and Amazon Lex knows to ask about these things.
Amazon Lex pricing model
Although it’s free to build a chatbot with Amazon Lex, AWS will charge a fee when people start interacting with your bot. You’re billed monthly according to the number of requests your bot receives, whether text or voice. Here’s the current price breakdown:
- $0.004 per speech request
- $0.00075 per text request
So, for a bot that processes 5,000 speech requests and 2,000 text requests in a given month, you’d pay $20.00 for the speech requests and $1.50 for the text requests.
Supported programming languages
Amazon Lex offers a variety of developer tools, including integrated AWS services for hosting your own source control system (AWS CodeCommit), compiling code (AWS CodeBuild), automating code deployments (AWS CodeDeploy), and leveraging the command line (AWS Command Line Interface). What might intrigue you the most, however, is the variety of software development kits (SDKs) available in different languages. Currently, the framework offers SDKs for the following languages:
There are also SDKs for Android, iOS, and React Native, so you can accelerate development for bots that you want to deploy as mobile apps.
The fact that there are so many SDKs for Amazon Lex speaks to the framework being part of the AWS services. These SDKs exist because so many developers with various programming backgrounds rely on AWS to build, run, and deploy their software. The AWS SDK for PHP, just to use one example, is not only available to developers using Amazon Lex but also available to all developers using AWS for anything.
Some other bot-building frameworks offer a similar variety of SDKs, but not all of them.
How machine learning works in Amazon Lex
Sample utterances. That’s how machine learning unfolds in Amazon Lex.
Basically, learning begins when you provide sample utterances (think interrogative and declarative statements) in English. These utterances help the framework build your bot’s language model, but they also serve as the spark that lights the fire of machine learning.
Drawing from the sample utterances, Amazon Lex learns the many ways a user expresses his or her intent. Per Amazon Lex documentation, as you continue to add utterances, Amazon Lex “generalizes from the samples...to recognize both exact matches and similar input.”
In other words, you teach your chatbot the basics. Then, after your bot gets the foundation from you, Amazon Lex helps it recognize real-world utterances that are different in form but identical in intent to the ones you taught the bot. The more sample utterances you provide, the more opportunities Amazon Lex has to build upon them.
How to get started with Amazon Lex
Getting started with Amazon Lex is easy—and it’s free.
Just log in to your AWS account or create one if you’re not an AWS customer yet. Then head over to the Amazon Lex “Getting Started” page, read through any recent related blog posts, download the documentation, and check out the recorded webinars. You can also check out this Amazon Lex video tutorial from AWS to get some other ideas for what types of intelligent chatbots you can build and what they are capable of doing.
Whether you’re building something simple or spearheading an effort to boost productivity at your organization, there are several good reasons to build your bot with Amazon Lex. Full-featured NLU and machine learning capabilities, SDKs in multiple languages, scalability and integrated deployment on popular platforms make Amazon Lex the go-to framework for many chatbot developers.