简体   繁体   中英

Boto3 - Create S3 'object created' notification to trigger a lambda function

How do I use boto3 to simulate the Add Event Source action on the AWS GUI Console in the Event Sources tab.

I want to programatically create a trigger such that if an object is created in MyBucket , it will call MyLambda function(qualified with an alias).

The relevant api call that I see in the Boto3 documentation is create_event_source_mapping but it states explicitly that it is only for AWS Pull Model while I think that S3 belongs to the Push Model. Anyways, I tried using it but it didn't work.

Scenarios:

  • Passing a prefix filter would be nice too.

I was looking at the wrong side. This is configured on S3

    s3 = boto3.resource('s3')
    bucket_name = 'mybucket'
    bucket_notification = s3.BucketNotification(bucket_name)
    response = bucket_notification.put(
        NotificationConfiguration={'LambdaFunctionConfigurations': [
            {
                'LambdaFunctionArn': 'arn:aws:lambda:us-east-1:033333333:function:mylambda:staging',
                'Events': [
                    's3:ObjectCreated:*'
                ],

            },
        ]})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM