|
1 | 1 | import boto3
|
2 | 2 | import json
|
3 | 3 |
|
4 |
| -def lambda_handler(event, context): |
5 | 4 |
|
6 |
| - # i want to know that event thing |
7 |
| - print(event) |
| 5 | +def lambda_handler(event, context): |
| 6 | + # i want to know that event thing |
| 7 | + print(event) |
8 | 8 |
|
9 |
| - # extract relevant information from the s3 event trigger |
10 |
| - bucket_name=event['Records'][0]['s3']['bucket']['name'] |
11 |
| - object_key=event['Records'][0]['s3']['object']['key'] |
| 9 | + # extract relevant information from the s3 event trigger |
| 10 | + bucket_name = event['Records'][0]['s3']['bucket']['name'] |
| 11 | + object_key = event['Records'][0]['s3']['object']['key'] |
12 | 12 |
|
13 |
| - # perform desired operations with the upload file |
14 |
| - print(f"File '{object_key}' was uploaded to bucket '{bucket_name}'") |
| 13 | + # perform desired operations with the uploaded file |
| 14 | + print(f"File '{object_key}' was uploaded to bucket '{bucket_name}'") |
15 | 15 |
|
16 |
| - # example: send a notification via sns |
17 |
| - sns_client=boto3.client('sns') |
18 |
| - topic_arn='arn:aws:sns:us-east-1:<account-id>:s3-lambda-sns' |
19 |
| - sns_client.publish( |
20 |
| - TopicArn=topic_arn, |
21 |
| - Subject='s3 object created !!', |
22 |
| - Message=f"File '{object_key}' was uploaded to bucket '{bucket_name}" |
23 |
| - ) |
| 16 | + # example: send a notification via SNS |
| 17 | + sns_client = boto3.client('sns') |
| 18 | + topic_arn = 'arn:aws:sns:us-east-1:<account-id>:s3-lambda-sns' |
| 19 | + sns_client.publish( |
| 20 | + TopicArn=topic_arn, |
| 21 | + Subject='s3 object created !!', |
| 22 | + Message=f"File '{object_key}' was uploaded to bucket '{bucket_name}'" |
| 23 | + ) |
24 | 24 |
|
25 |
| - # Example: Trigger another Lambda function |
26 |
| - # lambda_client = boto3.client('lambda') |
27 |
| - # target_function_name = 'my-another-lambda-function' |
28 |
| - # lambda_client.invoke( |
29 |
| - # FunctionName=target_function_name, |
30 |
| - # InvocationType='Event', |
31 |
| - # Payload=json.dumps({'bucket_name': bucket_name, 'object_key': object_key}) |
32 |
| - # ) |
33 |
| - # in case of queuing and other objective similar to the netflix flow of triggering |
| 25 | + # Example: Trigger another Lambda function |
| 26 | + # lambda_client = boto3.client('lambda') |
| 27 | + # target_function_name = 'my-another-lambda-function' |
| 28 | + # lambda_client.invoke( |
| 29 | + # FunctionName=target_function_name, |
| 30 | + # InvocationType='Event', |
| 31 | + # Payload=json.dumps({'bucket_name': bucket_name, 'object_key': object_key}) |
| 32 | + # ) |
| 33 | + # in case of queuing and other objectives similar to the Netflix flow of triggering |
34 | 34 |
|
35 |
| - return { |
36 |
| - 'statusCode': 200, |
37 |
| - 'body': json.dumps("Lambda function executed successfully !!") |
38 |
| - } |
| 35 | + return { |
| 36 | + 'statusCode': 200, |
| 37 | + 'body': json.dumps("Lambda function executed successfully !!") |
| 38 | + } |
0 commit comments