amazon-web-services - 启用 Amazon S3 存储桶以使用 SAM 触发 Lambda 函数

标签 amazon-web-services amazon-s3 aws-cloudformation aws-devops

每当使用 SAM 将文件上传到具有特定前缀和后缀的 Amazon S3 存储桶时,我想触发 Lambda 函数。现在我正在使用这段代码,但它给出了错误

ARN 格式不正确(服务:Amazon S3;状态代码:400;错误代码:InvalidArgument

Code

enter image description here

编辑:

2nd way to do this 这是有效的,但它没有提供添加后缀或前缀的选项。

最佳答案

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::FunctionEvents)允许 S3 调用您的 lambda 函数。

关于amazon-web-services - 启用 Amazon S3 存储桶以使用 SAM 触发 Lambda 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68743711/

相关文章:

python - 调用PutObject操作时发生错误(AccessDenied): Access Denied python

amazon-web-services - 如何实现重新烘焙 AMI 的一致性

amazon-web-services - AWS 云信息 : Is it possible to access user id inside a Cloudformation template?

amazon-web-services - Cloudformation 条件语句

python - 将 Glue Connection 资源的值传递给 Python Job

amazon-web-services - 如何在 AppDrag 上导出我的项目?

apache-spark - Spark 是否支持使用 Parquet 文件进行分区修剪

amazon-web-services - 如何通过 aws cli 在 Amazon s3 中重命名 "PREFIX"?

amazon-web-services - 使用 SDK 检查 Cognito 域前缀可用性

amazon-web-services - 无法连接到我的 ec2 实例