AWS CLI for Conversational Interfaces
Last Updated :
25 Oct, 2024
Chatbots and voice assistants have now made it easy for users to have conversations with applications, AWS has services—Amazon Lex and Amazon Polly, to name a few—that make the development of intelligent applications easier. But the AWS CLI makes it easy to manage these services programmatically. AWS CLI is used by developers to manage bots, sessions, and intents of conversational interfaces using just a couple of simple command-line commands. This article explains how to use AWS CLI to effectively manage conversational interfaces while giving an introduction to some key concepts, commands, and real-world examples.
Primary Terminologies
- AWS CLI: The AWS CLI provides a single tool for all AWS services and is used to run and manage multiple such services. By using only one tool to manipulate so many different AWS services, developers could easily automate and control their infrastructure with command line scripts.
- Amazon Lex: Amazon Lex is a service provided by AWS that enables the user to create any form of conversational interface, voice or text, and delivers advanced functionality to these interactions by using automatic speech recognition (ASR) and natural language understanding (NLU).
- Intent: An intent in Amazon Lex is an aim or objective that a user tries to achieve. For example, the intent may be to reserve a flight, order a pizza, or check the weather.
- Slot: A slot is an information entity needed to fulfill an intent; for example, flight booking may require slots to hold information about the departure city, destination city, and travel dates.
- Utterances: These are possible phrases, or alternatively, words that a user might say while interacting with the system in question, thus facilitating the comprehension of different ways of asking the same question or command by the bot.
- Amazon Polly: Amazon Polly is a service that turns text into lifelike speech, allowing developers to create applications that talk and build totally new categories of conversational and interactive experiences.
Architecting AWS CLI for Conversational Interfaces: Integrating Lex and Polly
Here's a visual representation of how AWS CLI interacts with conversational AI services like Amazon Lex and Amazon Polly. This architecture demonstrates the seamless integration between these components to create efficient and scalable conversational interfaces
Step-by-Step Process: Managing Conversational Interfaces Using AWS CLI
Now configure AWS by providing Access Key and Secret Key
aws configure
To Config AWS CLI Please Refer To Our Article - AWS CLI Configuration
Step 2: Define Your Intent
Create a JSON File for the Intent
Create a file named intent-definition.json
with the following content:
{
"name": "BookFlight",
"description": "An intent for booking flights",
"sampleUtterances": [
"I want to book a flight",
"Book a flight for me",
"Book a ticket from {Origin} to {Destination}"
],
"slots": [
{
"name": "Origin",
"slotType": "AMAZON.City",
"slotConstraint": "Required",
"valueElicitationPrompt": {
"messages": [
{
"content": "Where are you flying from?",
"contentType": "PlainText"
}
],
"maxAttempts": 2
}
},
{
"name": "Destination",
"slotType": "AMAZON.City",
"slotConstraint": "Required",
"valueElicitationPrompt": {
"messages": [
{
"content": "Where are you flying to?",
"contentType": "PlainText"
}
],
"maxAttempts": 2
}
}
],
"fulfillmentActivity": {
"type": "ReturnIntent"
}
}
Step 3: Create the Intent
Use the AWS CLI to create the intent:
aws lex-models put-intent --name "BookFlight" --region us-east-1 --cli-input-json file://intent-definition.json
Step 4: Define Your Bot
Create a JSON File for the Bot
Create a file named bot-definition.json
with the following content:
{
"name": "ChatBot",
"description": "A sample Lex bot for flight booking",
"locale": "en-GB", // Change this to the desired locale
"intents": [
{
"intentName": "BookFlight",
"intentVersion": "$LATEST"
}
],
"abortStatement": {
"messages": [
{
"content": "Sorry, I couldn't process your request. Please try again later.",
"contentType": "PlainText"
}
]
},
"clarificationPrompt": {
"maxAttempts": 2,
"messages": [
{
"content": "Sorry, I didn't understand. Can you please repeat?",
"contentType": "PlainText"
}
]
},
"childDirected": false,
"idleSessionTTLInSeconds": 300
}
Step 5: Create the Bot
Use the AWS CLI to create the bot:
aws lex-models put-bot --name "ChatBot" --region us-east-1 --cli-input-json file://bot-definition.json
Now wait for some time it take time to create. We can check status by using following command
It change status BUILDING to READY
aws lex-models get-bot-versions --name "ChatBot" --region us-east-1
Step 6: Create a Bot Alias
Before going to create a Bot Alias update Bot version by using following command
aws lex-models create-bot-version --name "ChatBot" --region us-east-1
Create a Bot Alias
Use the AWS CLI to create an alias for the bot:
aws lex-models create-bot-alias --bot-name "ChatBot" --bot-version "1" --name "Prod" --region us-east-1
Step 7: Test the Bot
Test the Bot Using post-text
Use the AWS CLI to send a test message to the bot:
aws lex-runtime post-text --bot-name "ChatBot" --bot-alias "Prod" --user-id "test-user" --input-text "I want to book a flight"
Provide Slot Value for Origin
You need to send the value for the Origin
slot. You can do this by sending another request with the slot value:
aws lex-runtime post-text --bot-name "ChatBot" --bot-alias "Prod" --user-id "test-user" --input-text "I am flying from New York"
Provide Slot Value for Destination
Once you provide the Origin
, the bot will ask for the Destination
slot. You need to send the value for Destination
:
aws lex-runtime post-text --bot-name "ChatBot" --bot-alias "Prod" --user-id "test-user" --input-text "I want to go to Los Angeles"
Step 8: Enable Text-to-Speech with AWS Polly
Amazon Polly can be integrated with your bot to convert text responses into speech.
aws polly synthesize-speech --text "Hello! How can I assist you today?" --output-format mp3 --voice-id Joanna chatbot-response.mp3
Use a media player to listen to the generated speech output.
To download the file to your local machine:
Use scp
(Secure Copy Protocol) if you're working from a local machine with access to the EC2 instance:
scp -i /path/to/your/key.pem ec2-user@<EC2-Instance-IP>:/home/ec2-user/chatbot-response.mp3 /local/directory/
Now we can check our downloaded file in our local system
Here is the Audio to listen
Conclusion
AWS CLI provides automation and simplification capabilities to do tasks under services like Amazon Lex and Amazon Polly. With the help of the AWS CLI, developers can efficiently create, update, and test conversational bots for text and voice interaction. This will enhance productivity, reduce the time taken up by manual configuration, and lead to flexible chatbot development that can scale up. This can help build simple text-based chatbots or more advanced voice-assisted interfaces that manage the full flow of conversational systems for the developer using this tool.
Similar Reads
AWS CLI for Continuous Integration
Quick and efficient delivery of quality code is at the core of software development in the fast-paced arena. Practically, Continuous Integration (CI) has emerged as a lynchpin practice to this aim, where developers regularly integrate changes in the code into the shared repository. These integration
6 min read
Design practices for Chatbots and Conversational UI
Living in the 21st century and who do not use AI tools like ChatGPT to ease their tasks minimize their efforts and maximize their output. There'd be hardly someone except the content writers! Tools like ChatBot & Conversational UI have made our lives easier to a much better and greater extent. W
5 min read
What is a Conversational UI?
Conversational User Interface (CUI) is a type of user interface that facilitates interaction between humans and machines through natural language conversations. Conversational UIs can take various forms, such as chatbots, virtual assistants, voice assistants, or messaging apps. These interfaces can
6 min read
Building Conversational AI Agents with LLMs
Conversational agents, or chatbots, have become integral to various applications, from customer service to virtual assistants. The advent of advanced language models (LLMs) like GPT-4 has significantly enhanced the capabilities of these agents, making them more intuitive, context-aware, and engaging
5 min read
How to Use AWS CLI in Docker Container ?
The AWS Command Line Interface (CLI) is a powerful tool that allows users to interact with AWS services directly from the terminal. Integrating AWS CLI within a Docker container can significantly streamline workflows, especially for development and deployment processes that rely on cloud infrastruct
4 min read
AWS CLI for Service Health Monitoring
AWS has numerous services, and for your application to run smoothly, it is necessary to keep a check on the status of the services. AWS CLI provides a unified set of commands that enable you to programmatically monitor the health and status of AWS services and resources. Monitoring service health th
6 min read
Differences between Conversational AI and Generative AI
Artificial intelligence has evolved significantly in the past few years, making day-to-day tasks easy and efficient. Conversational AI and Generative AI are the two subsets of artificial intelligence that rapidly advancing the field of AI and have become prominent and transformative. Both technologi
8 min read
AWS CLI for Relational Database Service
As we know, Amazon Web Services (AWS) provides more than 200 IT and infrastructure management services. The question arises: can we only access and manage those services through the AWS Management Console? The answer is no. We can access and interact with those services through the AWS Management Co
7 min read
Conversational Design / Conversational UX
With the rise in demands of chatbots and voice assistants, there was and still is an issue of chatbots sounding too much like robots and less like humans. This contributes to a poor user experience. This is where Conversation design comes to the rescue. Conversation design makes chatbots and voice a
5 min read
What Is AWS CLI (Command Line Interface) ? Complete Guide
AWS CLI is a command line tool that is used for managing the AWS Services from the command line. On downloading the AWS CLI software and configuring it with your AWS credentials you can control the AWS services from the command line and can automate the work through scripts. Whether you are launchin
13 min read