Skip to content

Instantly share code, notes, and snippets.

@saggie
Last active May 17, 2020 06:00
Show Gist options
  • Save saggie/98782d583df2f892b10c0890bceaef6f to your computer and use it in GitHub Desktop.
Save saggie/98782d583df2f892b10c0890bceaef6f to your computer and use it in GitHub Desktop.
Notify all generic events on CodeCommit to Teams Webhook
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