Created
January 19, 2022 13:10
-
-
Save HrushikeshK/cc26f7f6b0f712ac7aadc02793eb0fe7 to your computer and use it in GitHub Desktop.
Slack sending alert for Deactivate lambda
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
url = os.environ['WEBHOOK_URL'] | |
headers = { | |
'Content-Type': "application/json", | |
'User-Agent': "PostmanRuntime/7.19.0", | |
'Accept': "*/*", | |
'Cache-Control': "no-cache", | |
'Postman-Token': "59df68df-XXXX-XXXX-XXXX-9a2k5q56b8gf,458sadwa-XXXX-XXXX-XXXX-p456z4564a45", | |
'Host': "hooks.slack.com", | |
'Accept-Encoding': "gzip, deflate", | |
'Content-Length': "497", | |
'Connection': "keep-alive", | |
'cache-control': "no-cache" | |
} | |
def get_slack_payload(user, is_access_key, access_key="", arn="", diff=-1): | |
payload = "" | |
if diff == -1: | |
diff = "Never" | |
else: | |
diff = str(diff) + " days" | |
if is_access_key: | |
payload = """{ | |
\n\t\"channel\": \"#aws-iam-alerts\", | |
\n\t\"username\": \"IAM Bot\", | |
\n\t\"icon_emoji\": \":aws:\", | |
\n\t\"attachments\":[\n | |
{\n | |
\"fallback\":\"Access Key Deactivated\",\n | |
\"pretext\":\"Access Key Deactivated\",\n | |
\"color\":\"#34bb13\",\n | |
\"fields\":[\n | |
{\n | |
\"title\":\"*User:* """ + user + """\",\n | |
\"value\":\"*ARN:* """ + arn + """\n*Access Key:* """ + access_key + """\n*Last Accessed:* """ + diff + """ \"\n | |
}\n | |
]\n | |
}\n | |
]\n | |
}""" | |
else: | |
payload = """{ | |
\n\t\"channel\": \"#aws-audit-alerts\", | |
\n\t\"username\": \"IAM Bot\", | |
\n\t\"icon_emoji\": \":aws:\", | |
\n\t\"attachments\":[\n | |
{\n | |
\"fallback\":\"User Deactivated\",\n | |
\"pretext\":\"User Deactivated\",\n | |
\"color\":\"#34bb13\",\n | |
\"fields\":[\n | |
{\n | |
\"title\":\"*User:* """ + user + """\",\n | |
\"value\":\"*ARN:* """ + arn + """\n*Last Accessed:* """ + diff + """ \"\n | |
}\n | |
]\n | |
}\n | |
]\n | |
}""" | |
return payload |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment