Last active
January 13, 2022 11:29
-
-
Save righ/e592456f63e7718c83f52015442d1dd9 to your computer and use it in GitHub Desktop.
Lambda function for Sentry to Slack webhook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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