Last active
April 22, 2025 21:48
-
-
Save ivansabik/996086573d0460c640ed9afb979d7c10 to your computer and use it in GitHub Desktop.
Example implementation lambda for Monitoring of DMS Tasks on Slack from https://www.linkedin.com/pulse/monitoring-dms-tasks-slack-ruchi-khanuja
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 urllib3 | |
http = urllib3.PoolManager() | |
def lambda_handler(event, context): | |
""" | |
Example payload: | |
{ | |
"Records": [ | |
{ | |
"EventSource": "aws:sns", | |
"EventVersion": "1.0", | |
"EventSubscriptionArn": "arn:aws:sns:us-east-1:{{{accountId}}}:ExampleTopic", | |
"Sns": { | |
"Type": "Notification", | |
"MessageId": "95df01b4-ee98-5cb9-9903-4c221d41eb5e", | |
"TopicArn": "arn:aws:sns:us-east-1:123456789012:ExampleTopic", | |
"Subject": "example subject", | |
"Message": "example message", | |
"Timestamp": "1970-01-01T00:00:00.000Z", | |
"SignatureVersion": "1", | |
"Signature": "EXAMPLE", | |
"SigningCertUrl": "EXAMPLE", | |
"UnsubscribeUrl": "EXAMPLE", | |
"MessageAttributes": { | |
"Test": { | |
"Type": "String", | |
"Value": "TestString" | |
}, | |
"TestBinary": { | |
"Type": "Binary", | |
"Value": "TestBinary" | |
} | |
} | |
} | |
} | |
] | |
} | |
""" | |
sns_message = event["Records"][0]["Sns"]["Message"] | |
slack_message = { | |
"text": ("The DMS replication task has been stopped. " | |
"For more details go to https://us-west-2.console.aws.amazon.com/dms/v2/home?region=us-west-2#taskDetails/my-task" | |
f"\n```{sns_message}```") | |
} | |
response = http.request( | |
"POST", | |
"https://hooks.slack.com/services/bob/kevin/stuart", | |
body = json.dumps(slack_message), | |
headers = {"Content-Type": "application/json"}, | |
retries = False | |
) | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment