Sending SNS Notifications to HipChat

Over a year ago, I was working for a company fully adopting the AWS platform, working as part of the DevOps team, I was looking for ways to make everything a little easier and one of the things I had noticed was that we had set up our Auto Scaling Groups Notification emails – via Amazon’s SNS, which provided very useful information as and when we would scale up or down our instances, or had errors from failed random instance terminations at times.  But due to the information being delivered to us as emails, it wasn’t very visible and therefore useful as we had made HipChat our central communication channel.

So as with many other things, I went about investigating SNS to see how I could get that useful data into our HipChat rooms.

Amazon SNS has several different notification types, as I mentioned email. but also it can push notifications to SMS text messages, to its own SQS queues and the one which proved most useful to me, was to post notifications via HTTP(S).

By providing a means to send the payload of notification data to an endpoint of our choosing, I could then craft a service which would be able to present an endpoint, take in the SNS payload and convert the data into human readable text and send it off to HipChat.

So deciding on what to use as the service, I went for Sinatra, as its very lightweight and this service wouldn’t be doing much more than exposing a single endpoint which then enabled messages to get sent to a HipChat room.  As Sinatra’s written in Ruby, It meant I would then also get to leverage the hipchat-api gem which would do the HipChat sending work for me.

So on to the code, I basically wrote the application so that it exposed an endpoint for SNS HTTP like this.

post '/hipchat/:roomid' do
  data = JSON.parse(
  @hipchat_message = JSON.parse(data['Message'])
  hipchat_api ="#{ENV['HIPCHAT_AUTH_TOKEN']}")
  @status = hipchat_api.rooms_message(params[:roomid], 'Sns Topic', @hipchat_message, notify = 1, color = @message_color, message_format = 'html')

That’s the gist of it, feel free to have a look at the real thing.  Nothing special going on really, just parsing the json payload and presenting the information in a more readable format.  I make “bad” things like instance terminations appear as red notifiction messages in hipchat and “good” things like instance creations green – simple.  Alarms raised by SNS are detailed parsed as well.  I automatically confirm subscription to new topics in the code as this has to be done manually to protect against notification abuse I guess, but meant that you had to copy the SubscribeUrl data from the payload of the first message sent after creating a topic and request it from a browser.

Setting up SNS Notifications is easy and well documented by the AWS team so I won’t repeat that here.  You will select Http(s) and then enter the url to your server i.e, http://my.notification.service/hipchat/27463 (assuming 27463 is your room id)

Only other thing to do is to work out your room id in HipChat, but again I’ll assume that’s not an issue for you clever kids.

All of this when put together left us with some great results.



My New Blog!

Ok so take 2, I worked on my own site/blog using Ruby Rails back in September… it was never finished but was heading in the direction i wanted it to go. I set myself out a few requirements/tasks to accomplish as part of the rollout of

  1. Register DNS name – I used Namecheap as well the name suggest, it was cheap and i didn’t need a lot of the additional features I would get from other providers.
  2. Language – I opted for Ruby On Rails, it’s a great framework I’ve been using for some time now to get fully functional websites up and running in very little time.  I just couldn’t commit to implementing anything in .net MVC as I didn’t want the hassle if I’m honest, not to say it isn’t easy to have a blog site set up using MVC, but for me, it just isn’t AS easy as I have found to get there with Rails/Ruby.
  3. Host – By deciding on using Rails to create my blog engine – there was a host of freeware I could have used for site hosting, but as I am a AWS guy, I opted to host the site on the AWS free tier.
  4. Design – I opted for using Twitter Bootstrap UI as I wanted a clean simplistic look, and didn’t want to do any extra work for UI on different platforms – I have felt the pain of previously writing my own css that works on different browsers/devices and well its not worth the hassle to hear what I have to say.
  5. Things to help me – so RailsInstaller, AWS SDK for Ruby, a quick and dirty script to automate my initial setup on my CentOS Instance, a quick read on Rails Blog Engines and a useful bootstrap gem and my blog was up and running.
  6. What was next which never happened was integrating the commenting section using Disqus

And the results where er.. great…


I will go back to my original site when I can… unfinished business and all that. But for now… welcome to my blog 🙂