Building My First Slack Bot

Brett Gillett

Last week I attended my first DevOpsDays conference in Toronto. During the conference, I was introduced to something called an “open space.” Here’s an overview: everyone in attendance can throw out an idea about a topic that they would like to talk about, people vote, and discussions for the breakouts are selected based on interest.

One of the talks I attended was about something called ‘ChatOps.’ The idea is to use a chat client - like Slack - to help you manage day-to-day operations. A couple of examples that were discussed during the session were using a chat client to start deployments, or maybe as a tool for infrastructure status.

After the talk, I started to think about ways that I could use Slack to help with the day-to-day management of our AWS customers. One of the things that I find tedious is that I have to look up customer information regularly - information that I routinely look up may be monthly spending (or savings) or contact information, etc. Sure, we have all this information, but it spread across spreadsheets, our CRM tool, and tools that we use for billing, etc.

Having decided on what I wanted to build I spent some time over the weekend reading up on the Slack API and having a look at some examples from their GitHub repository and some Google searches. Overall, it was pretty easy to get something pieced together rather quickly to test out the idea. Here’s what I ended up doing:

First, I decided to call my Bot - Ruprecht, because you know that’s super important. After that, I decided that I would deploy my Slack Bot on a micro EC2 instance running within a VPC. I also set up a small RDS instance where I’ll store all my customer information. If I wanted to run this in production, I would have built a much more robust infrastructure, but this suits the situation.

Simple ChatOps AWS Architecture

Setting up my EC2 instance was super simple - two steps. I used a base AMI provided by AWS, and then I installed the MySQL Python Module, as well as the Slack Client for Python.

After getting the EC2 instance setup, I expanded on the RTM sample that Slack provided in their GitHub repository and added what I needed. For now, it’s pretty basic, but I can see potential ways to expand the Bot’s functionality in the future.

Here’s an example of how I asked my bot to tell me about the current AWS customers.

Example of using the AWS Ruprecht Bot

From here I plan on building API calls to AWS, and 3rd party tools that we use for billing. Long-term, I’ll work on ways to move to Lambda rather than having an EC2 instance for my Bot.

Brett Gillett


Like what you read? Why not subscribe to the weekly Orbit newsletter and get content before everyone else?