Make a chatbot — Manage AWS Servers

Start a simple ChatOps for AWS OpsWorks with Telegram Chatbot

Jeongsoo Park
Sep 10, 2017 · 5 min read
AWS OpsWorks

BotHub.Studio uses OpsWorks which is an AWS flavored Chef for server management. We can add or remove an instance for layers, deploy new codes of Git repository to servers.

When we adopted OpsWorks first, we use it through AWS web dashboard, but it was too cumbersome to log in, navigate along with lots of clicks. So we made a simple CLI script for frequent tasks such like add or remove an instance. But it also has a downside when moving across laptop and desktop, or a colleague wants to access. So we made a chatbot that helps such tasks.


  • Store access credentials to request API call to OpsWorks
  • Choose a stack to manage
  • Get layer list
  • Inform instance status in a layer
  • Execute a deployment command

Although more features can be added, I’ll narrow and focus to features above in this article.


Slack can be another option if your company already uses it. BotHub.Studio will support Slack soon.


On-boarding and get credentials

Credentials consist of access token and secret access token. BotHub.Studio SDK have a useful feature helps construct an intent made of several entities.

Add an intents entry to bothub.yml, which had made when you created a project.

You can add several intent entires under intents entry. An intent key in this file will be used as an argument name in code. We added an intent with a name credentials. Each intent has a slots, on_complete entry. (and on_complete can be omitted, and set_<intent_name> will be used for its name.) slots is a list of slots which consists of a slot ID and a question to ask.

Now when a user enters a /intent credentials command, chatbot asks a question of each slot step by step and keep its answers. on_complete functions will be executed when got all slot answers. Slot IDs defined at bothub.yml are function arguments name.

A user enters credentials and stores it in user storage with a key credentials.

When a user talks to our chatbot first time, it explains about itself, ask credentials to the user.

Telegram gives chatbot /start message when a conversation begins. So I implemented on_start methodto handle it. on_help method explains about commands supported.

Get a Stack list and choose a Stack

Choose a stack

We will use boto3 library to access OpsWorks. Add boto3 to requirements.txt file which is created in root directory when creating a new project.


I added two methods to manage stack and one utility method like below.

get_boto_client method creates and returns boto3 client object using credentials we input before.

/stack command returns a stack list the account has. Get stack list using boto3, put the result into a Message object and send to a messaging channel.

Show each stack as a button to response with ease, run stack select command (/use_stack) when clicked.

/use_stack command stores a selected stack ID to user storage and tells about commands user can use.

Get a list and inspect a Layer

Layer list and instance status

The repeated pattern continues:

/layers command shows layer list, layer name as a button and send /layer <layer_id> when clicking the button. /layer command prints an instance list and status of each instance of the layer.


Execute a deployment

As same with before, when a button clicked, the user send a command to the chatbot, chatbot sends a request to OpsWorks using boto3 and show the result with text and buttons.

When a user clicks Deploy button, chatbot shows apps of the stack and the user chooses an app, then chatbot shows deployment command list, the user chooses a command, chatbot starts a deployment.

I used a small trick to use an abbreviation for command argument in on_deploy_app() method to reduce a payload. Telegram limits payload of InlineKeyboardButton to 64bytes maximum.

You can find a complete code at GitHub repository.


We explored a simple usage here, but you can add more useful features for server management like to monitor server status, add an instance, change values for auto-scaling. You can also bind it to AWS CloudWatch to get notified when a situation occurs.

Register to BotHub.Studio and make your chatbot for free now.


News, tutorials about BotHub.Studio chatbot hosting service

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store