Articles

Send HipChat Notifications with SNS and Lambda


Communicate with your team using HipChat and Amazon AWS SNS and Lambda functions

Amazon AWS Lambda is a great service and really fun to use. In this article, I'm going to describe how we are using it for a project in combination with Amazon Simple Notification Service to send notifications to HipChat.

Create your Amazon AWS Lambda using NodeJS

The code for this Lambda function is written in nodejs, it uses the NodeJS 4.3 Runtime that Amazon has made recently available for the public.

In order for this to work, make sure your Lambda has Internet access. You can find the instructions on how to setup such a scenario in an earlier post that describes how to setup your VPCs and subnets so your Lambdas can have Internet access.

The function uses the HipChat API v1, which is deprecated but still available (and will be for a long time, apparently). It sends notifications through a simple HTTP request. The code for this lambda is available in this gist:

Go to your AWS Lambda Console and create a new function by pasting the code. Make sure you change the variables and arguments named token, room_id,and from to match your needs. Save your function and don't forget to setup your VPC and private subnet when configuring your function.

You can test the function with an event like this:

{
  "text": "hello world",
  "color": "green"
}

Create your Amazon AWS SNS Topic to route messages to your HipChat room

Head to your AWS SNS Console, click on Create New Topic, pick a name and save your new topic. Once created, locate it in the topics list, select it, and click on Create Subscription. As the protocol, choose AWS Lambda, and choose your newly created function in the Endpoint dropdown. Save it.

Test your HipChat and Amazon AWS SNS Integration

To test the function through SNS select your topic and click on Publish To Topic, use the following message that will be sent as the event argument of your lambda handler:

{
"default": "{\"text\": \"hello world\", \"color\": \"yellow\"}",
"lambda": "{\"text\": \"hello world\", \"color\": \"yellow\"}"
}

Integrate your development workflow and your team with HipChat notifications through Amazon AWS SNS

As you can see, SNS and Lambdas are absolutely fun to use! In no time we can integrate different kind of systems (in this case we chose HipChat, but Slack would work exactly the same -although with a different API, point taken-). Hint: we are actually using this from AWS CodeDeploy in order to receive notifications in our HipChat room as deploys go through their lifecycle. But I'm going to explain this in another article :).

Cheers!