Posted by & filed under aws, Deployments, DevOps.

We recently started working with Slack to streamline workflows and try some ChatOps. While pushing our Jenkins and Shippable updates to Slack was accomplished with a single cURL command, we also wanted our Elastic Beanstalk notifications to show up in some particular channels.

I’ve been wanting to try out AWS Lambda for some time now, and it just so happens that SNS (which Elastic Beanstalk uses for notifications) supports piping directly to a Lambda function.

The future of environment configuration is here.

Log into the AWS console, browse to the Lambda section and create a new function.

Name the function whatever you’d like — I’ve chosen “slackNotify”.

Make sure “Edit code in-line” is selected and paste the Gist below, replacing both instances of #mychannel and the Slack hook URL with your own:

Save the function, but don’t invoke it, otherwise you’ll get an error since the sample data won’t match what SNS will provide.

Setup SNS:

1. Head over to the SNS management page.

2. Click “Topics” and locate the topic for your Elastic Beanstalk environment. If you don’t have one, create a new topic and give a descriptive name that associates it with your environment.

3. Click the topic link and then “Create Subscription”.

The “Topic ARN” should already be filled in for you, but you’ll need to change “Protocol” to “AWS Lambda”. If you had to create a new topic, highlight the ARN and copy it to your clipboard (you’ll need it below). Now, the “Endpoint” drop-down should populate with the Lambda function we just created.

4. Choose the function and click “Create Subscription”.

If you didn’t already have an SNS topic associated with your Elastic Beanstalk environment, we’ll need to associate it with the topic you just created. The simplest way to do this is with the AWS CLI:

Armed with the ARN in your clipboard, we can associate it with our Elastic Beanstalk environment (Note: the next command will update your Elastic Beanstalk environment, potentially disrupting service. Use with caution!):

> aws elasticbeanstalk update-environment \
--environment-name ENVIRONMENT_NAME \
--option-settings Namespace=aws:elasticbeanstalk:sns:topics,OptionName="Notification Topic ARN",Value="TOPIC_ARN"

Replace ENVIRONMENT_NAME and TOPIC_ARN with the appropriate values and if that succeeds, you’ll see a JSON response letting you know your environment is updating.

If all goes well, your next successful or failed deployment should be posted to the Slack channel configured in your Lambda function.

— the behavior-driven marketing platform for developers.

2 Responses to “Post Elastic Beanstalk Notifications to a Slack Channel”

Leave a Reply

Your email address will not be published. Required fields are marked *