Amazon Web Services, AWS, Chatbot, Cloud, Infrastructure as a Code, Lambda, Lex, Python

Use AWS Lex chatbot to start and stop the AWS instance

February 28, 2018

Greetings!!

Technology is changing very rapidly now.  You can design, develop and make your application up and available within minutes(depends how quick you are at designing and coding).

I came across LEX recently. It is very easy to create your chatbot within minutes. You can teach your chatbot and then integrate with other services to deliver the desired result.

I have created a chatbot which helps you to start and stop AWS instance just by using chat. I have integrated this with Facebook chat, slack and twilio also. It is very easy.

Let’s get started.

Before you start you will need aws account. You can create free tier account here.

Login to you aws account and search for LEX service.

Select Create, on next screen you can create your own custom bot or select one of given samples for your understanding.

Let’s  click on “Custom Bot”. Under that there is text box for bot name, enter StartStopBot as bot name.

Leave other options as default and select create at end. A new IAM role would be created with required permissions.

I have created a lambda function which you can find here.

You need to create two intents StartServer and StopServer.  For StartServer screenshot are below same needs to be done for StopServer.

Please note the lambda function we created earlier is integrated here. Same function is called in both StartServer anf StopServer.

 

Once you have configured you can start chatting with your bot.

Server is started 🙂

Now let us stop server.

Server is stopped 🙂

I hope you enjoyed this.

Happy coding 🙂

You Might Also Like

2 Comments

  • Reply Ashwani September 21, 2019 at 1:15 pm

    Hi, how are you giving instance tags in slots, and what permission you are assigning to Lex , to access resources?

    • Reply admin September 30, 2019 at 1:55 pm

      Permission you need to provide according to services you are going to use, like in this case for lambda you need to provide access to start and stop the EC2 machine because it will be lambda interacting with EC2.

    Leave a Reply