import json
import urllib.request
def post_slack():
send_data = {
"username": "notify_slack",
"icon_emoji": ":vampire:",
"text": "test",
}
send_text = "payload=" + json.dumps(send_data)
method = 'POST'
headers = {'Content-Type': 'application/json'}
WEB_HOOK_URL = "https://hooks.slack.com/services/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"
# オブジェクトを組み立てる
request = urllib.request.Request(
WEB_HOOK_URL,
data=send_text.encode('utf-8'),
method=method
)
# ここで実際にPOSTが実行される
with urllib.request.urlopen(request) as response:
response_body = response.read().decode('utf-8')
# 最初にLambdaから呼ばれる
def lambda_handler(event, context):
response = post_slack()
return response