CloudAcademy
  1. Home
  2. Training Library
  3. Amazon Web Services
  4. Courses
  5. Working with Amazon Lex - Chatbots

Create Lex Bot with Intents and Slots

The course is part of this learning path

Applying Machine Learning and AI Services on AWS
course-steps 5 certification 1 lab-steps 2
play-arrow
Start course
Overview
DifficultyIntermediate
Duration49m
Students152

Description

In this Amazon Lex course you will be guided through an in-depth study of the Amazon Lex service. We review where and when to use this service to best effect. We'll go over Chatbots in general and why they have become both useful and popular. You will be introduced to the key features and core components within the Amazon Lex service. We spend time understanding and reviewing Amazon Lex Bots, Intents, Utterances, Slots, and Slot Types. 

We focus on the developer workflow and how Amazon Lex integrates seamlessly with other AWS services. We take a look at, and review the capabilities of the Amazon Lex API and associated SDKs. We review Versioning and Aliases and how they facilitate development within the Amazon Lex service. Finally, we walk you through building a fully functional chatbot implemented using the Amazon Lex service, which when completed will allow you to start and stop EC2 instances.

Learning Objectives 

  • Understand the basic principles of Amazon Lex for building Conversational Interfaces
  • Learn how to effectively use Amazon Lex to manage and maintain your own chatbots
  • Recognize and explain how to perform all basic Amazon Lex related tasks such as configuring Intents, Slots, and Lambda functions (code hooks)
  • Understand IAM security permissions required for Amazon Lex to interact with other AWS services such as EC2
  • Be able to competently manage Amazon Lex using the AWS console

Intended Audience

  • AWS Administrators
  • Software Developers and Engineers

Prerequisites

To be able to get the most out of this course we recommend having a basic understanding of:

  • Chatbots
  • AWS Lambda
  • Software Development
  • Basic understanding of Python

Coding Resources

The example code used within this course can be found here:

https://github.com/cloudacademy/lexstartstopinstances

Related Training Content

After completing this course we recommend taking the 'Introduction to Amazon Rekognition' course.

To discover more content like this, you will find all of our training in the Cloud Academy Content Training Library.

Transcript

- [Narrator] From within the services consult, open the Amazon Lex service in a new browser tab. Click on the Get Started button. This takes us into the Create your Lex bot view. Here, we can either spin up a sample Lex bot, one of either BookTrip, OrderFlowers, or ScheduleAppointment or in our case, we'll create and figure a Custom bot. Click on the Custom bot button to proceed. Within the Bot name, we enter the value StartStopInstancesBot, we select Matthew for the output voice, we set the session timeout to 10 minutes, and select No for an answer to the COPPA, Children's Online Privacy Protection Act question. We then click the Create button. We're now entered into the Editor view, for our StartStopInstancesBot.

Next, we add two new intents, the first intent there will be for starting instances. Click the Create new intent link. We then enter StartInstances for the name, and then click the add button. Next, we set up two utterances. Under Sample utterances, add start my instances please. Together with start my instances. We have no requirement for initialization and validation. But for point of reference, we highlight that its available if required. Next, we set up our slots. We have a single slot to set up, this will be the serverType and it will track whether we're starting the red, blue, or green instances. We need to create a custom slot type. We do so by clicking the plus button next to Slot types. Our custom slot type will be called InstanceType. And it will be configured to have the values red, green, and blue. Back within slots, we create out server types slot, and set the slot type to InstanceType that we just created. For the prompt, we enter the string what instance TYPE would you like to START?

Make sure to click the plus button to add the slot to our configuration. Next, enable the configuration prompt, and under Confirm, add the following string. Are you sure you would like to START {serverType} Instances? Ensuring that {serverType} is enclosed in curly brackets, as it's a slot. Under Cancel, add the following string. Okay, your {serverType} instances were NOT STARTED. Again, ensuring that {serverType} is enclosed in curly brackets, as it's a slot. Next, we configure the Fulfillment method for our bot. In this case, we select the StartStopInstances Python Lambda function that we previously set up. In doing so, we're then asked to agree to giving Amazon Lex permission to invoke our Lambda Functions. We do so by clicking the Okay button. Finally, click the Save Intent button at the bottom of the screen, this saves our StartInstances intent. We now repeat the same process for the StopInstances intent.

Click the Create new intent link. We then enter StopInstances for the name, and then click the Add button. Next, we set up two utterances. Under Sample utterances, add stop my instances please, together with stop my instances. Within slots, we create our serverType slot, and set the slot type to InstanceType that we previously created. For prompt, we enter the string what instance type would you like to STOP? Make sure to click the plus button to add the slot to our configuration. Next, enable the configuration prompt, and under confirm, add the following string. Are you sure you'd like to STOP {serverType} instances? Ensuring that {serverType} is enclosed in curly brackets, as it is a slot. Under Cancel, add the following string. Okay your {serverTYPE} instances were NOT STOPPED. Again, ensuring that {serverType} is enclosed in curly brackets, as it's a slot. Next, we configure the Fulfillment method for our bot. In this case, we select the StartStopInstances Python Lambda function that we previously set up. Finally, click the Save Intent button at the bottom of the screen. This saves our StopInstances intent.

At this stage, we're ready to build. At the top of the StartStopInstances bot screen, click the Build button. This will build and compile our Lex bot, allowing us to then begin testing it. The Build step takes approximately 30 seconds to complete. When the Build phase completes, the Test Bot pane on the right side is automatically opened for us. Here, we can begin to test our bot, but before we do, let's quickly check on the stages of our EC2 instances. Refreshing, we can see that all of our six instances are in a stopped setting.

Back within the Lex consult, let's test out our bot. Select the StartInstances tab, and copy the first utterance. In the test bot pane, paste the utterance. The bot should reply with the message asking, "What instance TYPE would you like to START?" Reply with "red," but before we do, take a quick look at the below detailed response. This shows the messages that were passed on the wire, and is a useful view to understand what is happening on the wire. Moving on, submitting the term "red" into the conversation, have the bot present a confirmation response. We enter "yes" and are informed that the EC2 instances with tag red were started successfully. Jumping back into the EC2 services consul, refreshing the view, we can see, indeed, that both red instances are booting up. A great result, we can now use the bot interface to start up the remainder of our instances, the green and blue instances. Let's go ahead and do this.

About the Author

Students5701
Labs6
Courses41
Learning paths8

Jeremy is a Cloud Researcher and Trainer at Cloud Academy where he specializes in developing technical training documentation for security, AI, and machine learning for both AWS and GCP cloud platforms.

He has a strong background in development and coding, and has been hacking with various languages, frameworks, and systems for the past 20+ years.

In recent times, Jeremy has been focused on Cloud, Security, AI, Machine Learning, DevOps, Infrastructure as Code, and CICD.

Jeremy holds professional certifications for both AWS and GCP platforms.