Skip to content

Instantly share code, notes, and snippets.

@righ
Last active January 13, 2022 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save righ/e592456f63e7718c83f52015442d1dd9 to your computer and use it in GitHub Desktop.
Save righ/e592456f63e7718c83f52015442d1dd9 to your computer and use it in GitHub Desktop.
Lambda function for Sentry to Slack webhook
import json
import urllib.request
WEBHOOK_URL = "https://hooks.slack.com/services/XXXXXXXXXX/YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY"
MESSAGE_TEMPLATE = """<{url}|{message}>"""
def lambda_handler(event, context):
post(event)
return {"statusCode": 200}
def post(event):
message = MESSAGE_TEMPLATE.format(**json.loads(event["body"]))
payload = json.dumps({"text": message})
req = urllib.request.Request(
WEBHOOK_URL,
data=f"payload={payload}".encode("utf-8"),
method="POST",
)
urllib.request.urlopen(req)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment