Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vvalorous/41d6af7921134036db50e2fdc59fc80c to your computer and use it in GitHub Desktop.
Save vvalorous/41d6af7921134036db50e2fdc59fc80c to your computer and use it in GitHub Desktop.
Create an SNS Topic, with a Lambda function subscribed. Using the below handler, you can parse the vent object for your SNS message and pass it to a Slack webhook URL.
#!/usr/bin/python2.7
# https://gist.github.com/daniel-woods
import json
from urllib2 import urlopen, HTTPError, Request
def post_message(url, data):
req = Request(url, data)
f = urlopen(req)
response = f.read()
f.close()
def lambda_handler(event, context):
# Webhook URL, get this from the Slack channel.
url = "https://hooks.slack.com/services/XXXXXX/XXXXXXXX/XXXXxxxxXXXXxxxxXXXX"
msg = {
"channel": "#aws-sns",
"username": "webhookbot",
"text": event['Records'][0]['Sns']['Message'],
"icon_emoji": ":ghost:"
}
# Send the Message
str_msg = json.dumps(msg)
data = "payload=" + str_msg
post_message(url, data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment