Amazon Lex -Deep Dive
Creating a Lex Bot
The course is part of these learning paths
Welcome back. In this lecture, we'll walk you through the steps required to get a fully functioning Amazon Lex demo up and running. We'll guide you through the process of creating a chatbot interface that allows a user to start and stop a set of EC2 instances. The user will be able to either chat or vocalize the commands, such as, "Start my service, please", or "Stop my service, please". The chatbot, in turn, will ask the user which specific EC2 instances they'd like to start or stop. The user will be able to respond by stating the type of instance where type is a metadata tag applied to all instances. Finally, the chat bot will ask for confirmation to proceed or not. Architecturally, the demo will consist of three main components. First, a pool of EC2 instances. There's nothing special about these instances, other than that they carry a metadata tag named type, which will be set to either red, green, or blue. Next, we create and configure a lambda function.
The lambda function performs the work of starting or stopping the EC2 instances, filtered on the supplied type tag value. The lambda function is offered in Python 3.6 and utilizes the OTO three library to interface with the AWS EC2 API. Finally, we set up a configure-it bot within Amazon Lex. The Lex bot will allow us to converse, either by chat or voice. Our conversational commands are processed by Lex and passed through to our lambda function. Let's get started! Within the AWS consult, select the EC2 service. Here, we'll create a set of EC2 servers.
Within the EC2 console, click the launch instance button. Select the Amazon Linux AMI. Since we are only interested in demonstrating the technique of using Lex to orchestrate the starting and stopping of our instances, we can safely go with a t2.nano, for instance type. Next, let's move onto the configuration instance section. Here, let's launch two instances into a VPC of our choosing. Here, the specific VPC we choose doesn't matter. Click through to the storage section, and accept the defaults. On the add tags section, ensure that we apply two tags. The first is the type tag. Here, we set the type tag to have the value red. The second tag is the standard name tag. Here, we set the name tag to have the value red instance. Click through to the security group section. Here, we'll create and attach an empty security group. Again, we're just focusing our demonstration on starting and stopping our instances via Lex, nothing more. Therefore, we don't need to allow any traffic access to the instances. Finally, click on the review and launch button, and launch with an existing SSH key. We'll now go back into the EC2 service, and repeat the same launch process, but this time, launching two more EC2 instances, with the type tag set to the value green, and the name tag set to the value green instance. Repeating this process one more time, we go back into the EC2 service and launch another two EC2 instances, this time with the type tag set to the value blue, and the name tag set to the value blue instance.
Concluding the EC2 launch steps, we should have, in total, six EC2 servers. Two with a type tag set to red, two with a type tag set to green, and two with a type tag set to blue. All of the six EC2 servers, in time, should achieve a running state. Next, well create and configure our lambda function. Click on services, and select the lambda service, opening it in a new browser tab. Click the create function button, to begin the process of setting up our custom lambda function. Next, click on the Author from scratch button. We give our new lambda function the name StartStop instances. For the IAM role, we select the create a custom role option. This opens a new browser tab, and begins the IAM one-click role creation step. Note here, the IAM role being created for us will be named lambda basic execution. Click the allow button. This creates the IAM role for us, and closes the tab, taking us back to the lambda function conflict tab. We then click the create function button. This takes us into the StartStop instances lambda function. We now need to set the runtime to be Python 3.6 and upload a ZIP package containing our source code. Our source code for this lambda function is stored in a Cloud Academy GitHub repo. Let's head over to this repo now. Take note of the repo URL. Scrolling down, we can see an architectural overview of the complete Amazon Lex demonstration we're building. Scrolling back up, click on the clone, or, download button, and take a copy of the clone URL. We'll now switch over to our terminal, and git-clone the repository.
Jeremy is a Content Lead Architect and DevOps SME here at Cloud Academy where he specializes in developing DevOps technical training documentation.
He has a strong background in software engineering, and has been coding with various languages, frameworks, and systems for the past 25+ years. In recent times, Jeremy has been focused on DevOps, Cloud (AWS, Azure, GCP), Security, Kubernetes, and Machine Learning.
Jeremy holds professional certifications for AWS, Azure, GCP, Terraform, Kubernetes (CKA, CKAD, CKS).