Last active
July 15, 2024 11:11
-
-
Save overnew/615dcbbfd77ba5a2be1c9a3959ff4cae to your computer and use it in GitHub Desktop.
lambda_warmstart_example.py
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
import json | |
import urllib3 | |
import os | |
# 환경 변수는 다시 가져올 필요가 없음!!! 전역에 | |
slack_webhook_url = os.environ['SLACK_WEBHOOK_URL'] | |
def lambda_handler(event, context): | |
# 매개변수의 추출은 항상 이뤄져야 함. | |
message = json.loads(event['Records'][0]['Sns']['Message']) | |
alarm_name = message['AlarmName'] | |
description = message['AlarmDescription'] | |
region = message['Region'] | |
time = message['StateChangeTime'] | |
slack_message = { | |
"blocks": [ | |
{ | |
"type": "header", | |
"text": { | |
"type": "plain_text", | |
"text": "경고: " + alarm_name | |
} | |
} | |
] | |
} | |
http = urllib3.PoolManager() | |
# Slack 메시지 전송 | |
try: | |
response = http.request('POST', slack_webhook_url ,headers={'Content-Type': 'application/json'},body=slack_message) #환경변수 | |
except Exception as e: | |
print(e) | |
raise e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment