-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda_function.py
More file actions
29 lines (25 loc) · 924 Bytes
/
Copy pathlambda_function.py
File metadata and controls
29 lines (25 loc) · 924 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
import json
import boto3
def lambda_handler(event, context):
for i in event["Records"]:
action = i["eventName"]
ip = i["requestParameters"]["sourceIPAddress"]
bucket_name=i["s3"]["bucket"]["name"]
object_name = i["s3"]["object"]["key"]
client = boto3.client("ses")
subject = str(action) + 'Event From '+bucket_name
body="""
<br>
This email is to notify you regarding {} event.
<br>
SourceIP : {} <br/>
Bucket Name : {} <br/>
Object : {}
""".format(action,ip,bucket_name,object_name)
message = {"Subject" :{"Data":subject},"Body":{"Html":{"Data":body}}}
response=client.send_email(Source="avinashbasetty@gmail.com", Destination = {"ToAddresses":["avinashbasetty@gmail.com"]},Message=message)
# TODO implement
return {
'statusCode': 200,
'body': json.dumps('Notification is successful!')
}