Use AWS Lex chatbot to start and stop the AWS instance


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 šŸ™‚

This article has 3 comments

  1. Ashwani Reply

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

    • admin Reply

      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.

  2. fawaz Reply

    Br0 I am getting the following error in lambda for startstop lex program
    “errorMessage”: “‘bot'”,
    “errorType”: “KeyError”,
    “stackTrace”: [
    ” File \”/var/task/\”, line 109, in lambda_handler\n logger.debug(‘{}’.format(event[‘bot’][‘name’]))\n”

Leave a Comment

Your email address will not be published. Required fields are marked *