Boto3 - 创建 S3 'object created' 通知以触发 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 拉模型,而我认为 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:*'
],
},
]})
如何使用 boto3 在 Event Sources
选项卡中的 AWS GUI 控制台上模拟 Add Event Source
操作。
我想以编程方式创建触发器,这样如果在 MyBucket
中创建对象,它将调用 MyLambda
函数(使用别名限定)。
我在 Boto3 文档中看到的相关 api 调用是 create_event_source_mapping
,但它明确指出它仅适用于 AWS 拉模型,而我认为 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:*'
],
},
]})