0

How to add the s3 trigger(including prefix, suffix, bucket, event type) to the specific Lambda function using botot3?

1
  • 1
    Could 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? Commented Jul 25, 2018 at 21:33

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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?
@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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.