-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda_handler.py
More file actions
37 lines (28 loc) · 887 Bytes
/
lambda_handler.py
File metadata and controls
37 lines (28 loc) · 887 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/python3.9
import urllib3
import json
http = urllib3.PoolManager()
def lambda_handler(event, context):
url = event['slack_webhook'] # "<slack-webhook-url>"
msg = {
"channel": event['channel'], # "<slack-channel>"
"username": event['username'] # "AWS-LAMBDA",
"text": event['message']
}
encoded_msg = json.dumps(msg).encode('utf-8')
response = http.request('POST',url, body=encoded_msg)
print({
"message": event['message'],
"status_code": response.status,
"response": response.data
})
# return {
# "statusCode": response.status,
# "headers": {
# "Content-Type": "application/json"
# },
# "body": json.dumps({
# "message": event['message'],
# #"response": response.data
# })
# }