Blog
March 21, 2016 Marie H.

Setup Slack notification for AWS CodeDeploy

Setup Slack notification for AWS CodeDeploy

Photo by <a href="https://unsplash.com/@iridial_?utm_source=cloudista&utm_medium=referral" target="_blank" rel="noopener">iridial</a> on <a href="https://unsplash.com/?utm_source=cloudista&utm_medium=referral" target="_blank" rel="noopener">Unsplash</a>

CodeDeploy doesn’t come with a native way to integrate with third party services; so in order to integrate with a service you need to do a small workaround involving SNS and Lambda.

Setup SNS topic and Lambda

First you need to setup a SNS Topic “deployments” (Feel free to use your own topic name). Once that is done you need to hop on over to Lambda and find a SNS blueprint, I used sns-message-python with the event SNS and then set to the topic just created.

Next setup the basic execution role recommended by AWS (if you don’t have a role setup already).

Create your Lambda function

Updated 2026-03-20: Original used Python 2 (urllib2, urllib.urlencode). Updated to Python 3. Note: Slack's chat.postMessage API now recommends using their Incoming Webhooks instead of token-based URL params for simpler integrations.

import json
from urllib.parse import urlencode
from urllib.request import urlopen, Request

def send_slack(message):
    """
    Send Slack Message to Deployments Channel
    """
    slack_token = ''
    slack_channel = ''
    slack_user = 'Deployment Bot'
    slack_url = 'https://slack.com/api/chat.postMessage'
    payload = {
        "token": slack_token,
        "channel": slack_channel,
        "username": slack_user,
        "text": message
    }
    query_string = urlencode(payload)
    url = slack_url + '?' + query_string
    response = urlopen(url)

def lambda_handler(event, context):
    message = event['Records'][0]['Sns']['Message']
    send_slack(message)
    return message

Create a trigger on your CodeDeploy

I used the following triggers for notifications.

  • Deployment Starts

  • Deployment Succeeds

  • Deployment Fails

That’s it now everytime you deploy using CodeDeploy you can have a tracking log via Slack.

I am a huge fan of integrating slack with everything from saltstack to monitoring alerts. That way everything is in one place!