Skip to content

Instantly share code, notes, and snippets.

@richardgrantserverless
Created May 26, 2022 14:40
Show Gist options
  • Save richardgrantserverless/d373b707b92ea82d7085161ee17ab9a0 to your computer and use it in GitHub Desktop.
Save richardgrantserverless/d373b707b92ea82d7085161ee17ab9a0 to your computer and use it in GitHub Desktop.
# 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