Skip to content

Instantly share code, notes, and snippets.

@overnew
Last active July 15, 2024 11:11
Show Gist options
  • Save overnew/615dcbbfd77ba5a2be1c9a3959ff4cae to your computer and use it in GitHub Desktop.
Save overnew/615dcbbfd77ba5a2be1c9a3959ff4cae to your computer and use it in GitHub Desktop.
lambda_warmstart_example.py
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