Last active
May 17, 2020 06:00
-
-
Save saggie/98782d583df2f892b10c0890bceaef6f to your computer and use it in GitHub Desktop.
Notify all generic events on CodeCommit to Teams Webhook
This file contains hidden or 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 | |
teams_endpoint = "https://outlook.office.com/webhook/.../IncomingWebhook/..." | |
def build_text(message, detail): | |
body = json.dumps(detail, indent=2) | |
text = [] | |
text.append("## " + message["detailType"]) | |
text.append("<pre>" + body + "</pre>") | |
return text | |
def lambda_handler(event, context): | |
message = json.loads(event["Records"][0]["Sns"]["Message"]) | |
print("message: {}".format(message)) | |
detail = message["detail"] | |
text = build_text(message, detail) | |
body = {"text": "\n\n".join(text)} | |
req = urllib.request.Request( | |
teams_endpoint, | |
data=json.dumps(body).encode("utf8"), | |
headers={"content-type": "application/json"}, | |
) | |
urllib.request.urlopen(req) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment