简体   繁体   English

Boto3 - 创建S3'对象创建'通知以触发lambda函数

[英]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. 如何使用boto3在“ Event Sources选项卡中模拟AWS GUI控制台上的“ Add Event Source操作。

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). 我想以编程方式创建一个触发器,这样如果在MyBucket创建了一个对象,它将调用MyLambda函数(使用别名限定)。

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. 我在Boto3文档中看到的相关api调用是create_event_source_mapping但它明确指出它仅适用于AWS Pull Model,而我认为S3属于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上配置的

    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:*'
                ],

            },
        ]})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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