簡體   English   中英

Boto3 - 創建S3'對象創建'通知以觸發lambda函數

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

如何使用boto3在“ Event Sources選項卡中模擬AWS GUI控制台上的“ Add Event Source操作。

我想以編程方式創建一個觸發器,這樣如果在MyBucket創建了一個對象,它將調用MyLambda函數(使用別名限定)。

我在Boto3文檔中看到的相關api調用是create_event_source_mapping但它明確指出它僅適用於AWS Pull Model,而我認為S3屬於Push Model。 無論如何,我嘗試使用它,但它沒有用。

場景:

  • 傳遞前綴過濾器也很不錯。

我看錯了一面。 這是在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