How to add the s3 trigger(including prefix, suffix, bucket, event type) to the specific Lambda function using botot3?
1
-
1Could you please clarify your question? Are you asking how to configure the Amazon S3 bucket to trigger an AWS Lambda function, or are you asking how to write the Lambda function that is triggered by the event? For tips on asking a good question, please see: How do I ask a good question?John Rotenstein– John Rotenstein2018-07-25 21:33:04 +00:00Commented Jul 25, 2018 at 21:33
Add a comment
|
1 Answer
Something like this should do it:
s3 = boto3.resource('s3')
bucket_name = 'BUCKETNAME'
bucket_notification = s3.BucketNotification(bucket_name)
response = bucket_notification.put(
NotificationConfiguration={'LambdaFunctionConfigurations': [
{
'LambdaFunctionArn': 'ARN_OF_LAMBDA_FUNCTION',
'Events': [
's3:ObjectCreated:*'
],
},
]})
Obviously modify BUCKETNAME and ARN_OF_LAMBDA_FUNCTION to suit your needs.
2 Comments
anastasiia
but if I have a subfolder in my bucket and I upload files in a subfolder, how to specify that the function would be triggered only if specific subfolder got updated?
colde
@anastasiia you specify a filter like the last example here: docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/… and you can then use "prefix" instead of "suffix" and specify "subfolder/" in the Value.