每当使用 SAM 将文件上传到具有特定前缀和后缀的 Amazon S3 存储桶时,我想触发 Lambda 函数。现在我正在使用这段代码,但它给出了错误
“ARN 格式不正确(服务:Amazon S3;状态代码:400;错误代码:InvalidArgument”
编辑:
最佳答案
在 NotificationConfiguration
中,您只需使用 !Ref HelloWorld
来引用您的函数,但是,如 the documentation for AWS::Serverless::Function
状态:
When the logical ID of this resource is provided to the Ref intrinsic function, it returns the resource name of the underlying Lambda function.
如果我们看 the documentation for the LambdaConfiguration
它指出:
The Amazon Resource Name (ARN) of the AWS Lambda function that Amazon S3 invokes when the specified event type occurs.
如果您只是将 !Ref HelloWorld
更改为 !GetAtt HelloWorld.Arn
,它应该会传递正确的值。
但是请注意 the NotificationConfiguration
documentation 上的评论如果您在创建通知配置的同时创建存储桶,则可能会出现循环依赖关系,因为您还需要添加 AWS::Lamdba::Permission
(或使用 AWS::Serverless::Function
的 Events
)允许 S3 调用您的 lambda 函数。
关于amazon-web-services - 启用 Amazon S3 存储桶以使用 SAM 触发 Lambda 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68743711/