-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paths3-lambda-function.py
More file actions
33 lines (28 loc) · 1.13 KB
/
Copy paths3-lambda-function.py
File metadata and controls
33 lines (28 loc) · 1.13 KB
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
import boto3
import json
def lambda_handler(event, context):
# Extract relevant information from the S3 event trigger
bucket_name = event['Records'][0]['s3']['bucket']['name']
object_key = event['Records'][0]['s3']['object']['key']
# Perform desired operations with the uploaded file
print(f"File '{object_key}' was uploaded to bucket '{bucket_name}'")
# Example: Send a notification via SNS
sns_client = boto3.client('sns')
topic_arn = 'arn:aws:sns:us-east-1:<account-id>:s3-lambda-sns'
sns_client.publish(
TopicArn=topic_arn,
Subject='S3 Object Created',
Message=f"File '{object_key}' was uploaded to bucket '{bucket_name}'"
)
# Example: Trigger another Lambda function
# lambda_client = boto3.client('lambda')
# target_function_name = 'my-another-lambda-function'
# lambda_client.invoke(
# FunctionName=target_function_name,
# InvocationType='Event',
# Payload=json.dumps({'bucket_name': bucket_name, 'object_key': object_key})
# )
return {
'statusCode': 200,
'body': json.dumps('Lambda function executed successfully')
}