-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathLambda_code.py
More file actions
31 lines (26 loc) · 858 Bytes
/
Lambda_code.py
File metadata and controls
31 lines (26 loc) · 858 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
import boto3
import json
import requests
def lambda_handler(event, context):
# Get the S3 bucket and object key from the event
bucket = event['Records'][0]['s3']['bucket']['name']
key = event['Records'][0]['s3']['object']['key']
# Parse the filename (key)
filename = key.split('/')[-1]
# Send a request to the EC2 instance
ec2_url = "http://<Public-IP>/<folder_name to catch files in ec2>"
# Prepare the data to be sent
data = {
'bucket': bucket,
'key': key,
'filename': filename,
'sender_email': '<Email/Outlook ID>',
'sender_password': '<Password>',
'subject': '<Subject> ',
'body': '<body>'
}
response = requests.post(ec2_url, json=data)
return {
'statusCode': 200,
'body': json.dumps('Request sent to EC2')
}