-
-
Save richardgrantserverless/d373b707b92ea82d7085161ee17ab9a0 to your computer and use it in GitHub Desktop.
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
# handler.py | |
import json | |
import os | |
from botocore.vendored import requests | |
SLACK_URL = os.environ.get('SLACK_URL') | |
def create_table(event, context): | |
formatted = format_message(event) | |
send_to_slack(formatted) | |
def format_message(event): | |
detail = event.get('detail') | |
parameters = detail.get('requestParameters') | |
identity = detail.get('userIdentity') | |
table_name = parameters.get('tableName') | |
region = detail.get('awsRegion') | |
username = identity.get('userName') | |
user_type = identity.get('type') | |
text = '\n'.join([ | |
"New DynamoDB table created!", | |
"Table *{}* created in region *{}*".format(table_name, region), | |
"Request made by username *{}*, a *{}*.".format(username, user_type) | |
]) | |
return { | |
"text": text | |
} | |
def send_to_slack(message, url=SLACK_URL): | |
resp = requests.post(url, json=message) | |
resp.raise_for_status() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment