AWS ChatOps with Hubot & Slack

There can be many reasons for wanting to explore the use of Chatbots. In situations where collaboration tools like Slack are already in place, introducing a bot is merely another form of automation to support the way people work. In companies that are interested in providing a forum for people to develop technical skills, there are definite possibilities offered through Chatbots, especially as extending their functionality is not overly difficult and actually makes them more useful. For the enthusiast, Chatbots provide a glimpse into a future where interactions with technology are more fluid, based on natural language and conversation, but this is where challenges remain, for despite all the powerful technology that has been used to create Hubot, frankly it isn’t that chatty for a chatbot.

I suspect that many end-users would be disappointed with the way commands are needed for Hubot like pretty much any other software tool. I’d go as far as to say that the interface with Slack is the only “chatty” thing about it. I suspect I’m missing something or that chatbot is a misnomer. As yet, I haven’t been able to ask fuzzy questions like “what time is it?” or “what’s the time?” or “tell me the time please” and get the same result, so I need to look into that. I wonder if there is a script that can give Hubot more personality?

Hubot is able to do what’s asked of it, but so what?

There is a lot of powerful technology under the hood that is used to get Hubot to this point, so I’m sure at some sort of scale you will be able to see the wow factor, but a stand alone instance doesn’t really show that off. I think that if there was greater utilisation, to the point where the back-end was seeing heavy use (of components like Redis) then it would be easier to see the value.

Personally, the introduction to the node.js ecosystem was very interesting especially as it provides context for some real-world activities that are going on around me. I was impressed by how tools like NPM appear quite slick to the Node novice. Slack was also impressive, but again desperately needs users in order to be of value. I think that in the real world I am more likely to be encountering Hipchat (due to the value that can be gained from a Jira integration), but regardless of the technology I am excited at the prospect of a chat forum appearing in an enterprise setting.


Maybe the trick to Hubot is that in order for the bot to develop a personality, it needs to be crafted by the organisation that is using the bot. If Hubot provides a basic bot, the organisation that wants to use the bot can craft that personality. The first challenge that could be opened up to the company could be to work on the programming needed to build the firms Hubot something like a personality. Imagine offering that up to your end users in marketing? Hey, could you lash together a few lines of code and give our bot a soul?

I wonder what they would create?

Configure Hubot to run in background via systemd

In /etc/systemd/system create a “hubot.service” file and populate it as follows:

$ sudo vi hubot.service




ExecStart=/io/bin/hubot --adapter slack


Hubot uses environment variables to store certain parameters. In order for the systemd Hubot service to be make use of environment variables, a hubot.conf file is needed. This file needs to be stored in a specific location so that systemd can read it when starting the service.

In the example below you can see where I’ve configured the Slack Access Token as an environment variable to enable my Hubot to be able to connect to my Slack team.

$ sudo mkdir hubot.service.d

$ cd hubot.service.d

$ sudo vi hubot.conf



$ sudo systemctl daemon-reload

With systemd configured to operate Hubot, commands like service hubot start are now available.

Using systemctl enable hubot set systemd to start Hubot automatically whenever the server is restarted.

Here is the output of the service hubot status command after a reboot of the server:

$ sudo service hubot status
Redirecting to /bin/systemctl status hubot.service
● hubot.service - Hubot
Loaded: loaded (/etc/systemd/system/hubot.service; enabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/hubot.service.d
Active: active (running) since Sun 2016-08-21 18:07:47 IST; 10s ago
Main PID: 819 (node)
CGroup: /system.slice/hubot.service
└─819 node node_modules/.bin/coffee /io/node_modules/.bin/hubot --name io --adapter slack

systemd[1]: Started Hubot.
systemd[1]: Starting Hubot...
hubot[819]: [Sun Aug 21 2016 18:07:52 GMT+0100 (IST)] INFO Logged in as io of Chatty McChatface
hubot[819]: [Sun Aug 21 2016 18:07:53 GMT+0100 (IST)] INFO Slack client now connected
hubot[819]: [Sun Aug 21 2016 18:07:53 GMT+0100 (IST)] INFO hubot-redis-brain: Using default redis on localhost:6379
hubot[819]: [Sun Aug 21 2016 18:07:54 GMT+0100 (IST)] INFO hubot-redis-brain: Data for hubot brain retrieved from Redis

Cleaning up Hubot’s Configuration

With Hubot up and running and configured to do more than just display pictures of pugs, I noticed the status output of systemd was very noisy:

$ sudo service hubot start

$ sudo service hubot status

Redirecting to /bin/systemctl status  hubot.service

hubot.service - Hubot

Loaded: loaded (/etc/systemd/system/hubot.service; disabled; vendor preset: disabled)

Drop-In: /etc/systemd/system/hubot.service.d


Active: active (running) since Mon 2016-08-15 04:14:45 EDT; 26s ago

Main PID: 23105 (node)

CGroup: /system.slice/hubot.service

└─23105 node node_modules/.bin/coffee /io/node_modules/.bin/hubot --name io --adapter slack

Aug 15 04:14:45 systemd[1]: Started Hubot.

Aug 15 04:14:45 systemd[1]: Starting Hubot...

Aug 15 04:14:48 hubot[23105]: [Mon Aug 15 2016 04:14:48 GMT-0400 (EDT)] INFO Logged in as io of Chatty McChatface

Aug 15 04:14:49 hubot[23105]: [Mon Aug 15 2016 04:14:49 GMT-0400 (EDT)] INFO Slack client now connected

Aug 15 04:14:49 hubot[23105]: [Mon Aug 15 2016 04:14:49 GMT-0400 (EDT)] WARNING Loading scripts from hubot-scripts.json i... script.

Aug 15 04:14:49 hubot[23105]: Your hubot-scripts.json is empty, so you just need to remove it.

Aug 15 04:14:49 hubot[23105]: [Mon Aug 15 2016 04:14:49 GMT-0400 (EDT)] ERROR hubot-heroku-alive included, but missing HU...d= -f2)`

Aug 15 04:14:50 hubot[23105]: [Mon Aug 15 2016 04:14:50 GMT-0400 (EDT)] INFO hubot-redis-brain: Using default redis on lo...ost:6379

Aug 15 04:14:50 hubot[23105]: [Mon Aug 15 2016 04:14:50 GMT-0400 (EDT)] WARNING The HUBOT_AUTH_ADMIN environment variable not set

Aug 15 04:14:50 hubot[23105]: [Mon Aug 15 2016 04:14:50 GMT-0400 (EDT)] INFO hubot-redis-brain: Data for hubot brain Redis

Hint: Some lines were ellipsized, use -l to show in full.

In order to tidy up the log so that important items don’t get lost in the noise, I removed a couple of unnecessary items from Hubots configuration.

I deleted the “hubot-scripts.json” file, as Hubot no longer uses it. All that happens is a warning is thrown when Hubot starts – it’s harmless, I just removed it for the sake of a less noisy log.

I removed the reference to Heroku from the external-scripts.json file so that the Heroku connector didn’t get called when Hubot starts.

Using Hubot with Slack

Slack is the latest hip tool that technology teams have come to depend on. Based on an idea eerily similar to Internet Relay Chat (IRC) that was extremely popular back in the mid-nineties, Slack allows teams to collaborate in web and app based chat rooms and  is growing in popularity with enterprises as well as the smaller start-up world where it first took off, as larger businesses are realising that Slack provides a very neat audit trail through the log of the chats themselves.

2016-08-27 11_08_43-Slack_ Be less busy

Slack is extremely extensible, and this is where Hubot comes in. Slack is the perfect interface for Hubot as bots can be team members in Slack, appearing in chat rooms and interacting like everyone else.

Slack offers accounts at different price points, from no cost and quite restricted up to enterprise level that costs more but comes with all the bells and whistles. I dove in with a free account to facilitate testing of my bot.

Once the Slack account was up and running along with the associated team (which I couldn’t resist calling “Chatty McChatface”), I was ready to deploy my Hubot (Io).

In Slack, you simply navigate to the Apps directory and search for Hubot.

2016-08-27 11_18_12-Configure Apps _ Chatty McChatface Slack

There follows a handful of simple configuration steps which include generating an access token. This is important as that token is used on the server hosting Hubot to enable the connection with Slack, in much the same way as the access and secret keys enable access with AWS. (The next post will deal with environment variables like this one).

With Hubot configured in Slack (and connected on the server) it’s possible to use a chat room to interact with Hubot. Initially, the bot will have a direct or private room for 1:1 chat, like any team member. Here, simple tests can be carried out in private to ensure all is working as it should.

2016-08-27 11_30_40-io _ Chatty McChatface Slack

There’s far more value in having Hubot out in the open in one of the team rooms and enabling that is as simple as inviting Hubot to join the room, just like you would for a human team member, through the “/invite @[BOTNAME]” command.

2016-08-27 11_34_52-random _ Chatty McChatface Slack

Now that Hubot was in place and working, AWS functionality could be tested. The hubot-aws script features a lot of commands, but a simple listing (ls) command of one of the AWS services is enough to ensure connectivity. Like any good bot, Hubot will list all the commands he supports through the “help” command.

2016-08-27 11_37_52-random _ Chatty McChatface Slack

So there you have it, a working Hubot implementation, connected to and interacting with AWS, presented through Slack.

Up next, how to use Systemd to automate the running of Hubot.