amazon-s3 - 无法将通知配置添加到 s3 存储桶

标签 amazon-s3 aws-cloudformation sam

创建云形成模板以创建带有通知的存储桶。

以下是代码:

AWSTemplateFormatVersion: '2010-09-09'

Parameters:
  CBRS3ToS3IADelay:
    Description: Number of days before an S3 object is transitioned from S3 to S3-IA
    Type: Number
    Default: 365
  CBRS3ToGlacierDelay:
    Description: Number of days before an S3-IA object is transitioned from S3-IA to Glacier.
    Type: Number
    Default: 1460
  CBRBucketName:
    Description: S3 bucket name
    Type: String
    Default: "my-bucket-test0011"

Resources:
  CBRS3Bucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName:
        Ref: CBRBucketName
      AccessControl: Private
      LifecycleConfiguration:
        Rules:
          - Id: CbrCertReportGlacierArchiveRule
            Status: Enabled
            Transitions:
              - StorageClass: STANDARD_IA
                TransitionInDays: !Ref CBRS3ToS3IADelay
              - StorageClass: GLACIER
                TransitionInDays: !Ref CBRS3ToGlacierDelay
      NotificationConfiguration:
        LambdaConfigurations:
          -
            Function: "arn:aws:lambda:xxxx:xxxx:function:xxxx"
            Event: "s3:ObjectCreated:Put"
            Filter:
              S3Key:
                Rules:
                  -
                    Name: suffix
                    Value: ".gz"
      Tags:
        - Key: PRODUCT
          Value: CRAWS
      VersioningConfiguration:
        Status: Enabled

使用通知 block 的代码。 但上述模板不适用于通知。

出现以下错误:

Unable to validate the following destination configurations (Service: Amazon S3; Status Code: 400; Error Code: InvalidArgument

我可以从控制台执行操作。

有人帮我解决这个问题吗?

最佳答案

这已经晚了,所以更多的是回答我自己的这个问题(刚刚设法解决同样的问题):由于对 s3 调用该 lambda 函数的初步检查而失败,我们需要这个:

  CBRS3BucketCanInvokeFunctionX:
    Type: 'AWS::Lambda::Permission'
    Properties:
      FunctionName: ARN_OF_FUNCTION_X
      Action: 'lambda:InvokeFunction'
      Principal: s3.amazonaws.com
      SourceAccount: !Ref 'AWS::AccountId'
      SourceArn: !Sub 'arn:aws:s3:::${CBRBucketName}'

您的 CBRS3Bucket 还需要先运行上述资源:

  CBRS3Bucket:
    Type: AWS::S3::Bucket
    DependsOn: CBRS3BucketCanInvokeFunctionX

关于amazon-s3 - 无法将通知配置添加到 s3 存储桶,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53849098/

相关文章:

django - Webpack:使用 Django 存储从 S3 加载 Codesplit block

amazon-s3 - 在 CloudFormation yaml 中创建 BucketPolicy 时出错

amazon-web-services - 将未知大小的实例类型和权重容量列表添加到 AWS CF 模板中的 Auto Scaling 组 (YAML)

amazon-web-services - AWS SAM : An error occurred (ValidationError) when calling the CreateChangeSet operation: Parameter 'MaxAllowedPacket' must be a number

amazon-web-services - 云形成 : Waiter StackCreateComplete failed: Waiter encountered a terminal failure state

amazon-web-services - 如何读取雅典娜中的转义字符

sed - 使用带反斜杠的 sed 命令时 AWS CloudFormation 模板验证错误

ansible - 如何使用 Ansible 更新带有屏蔽参数的 CloudFormation 堆栈?

aws-cloudformation - SAM 部署失败错误 - Waiter StackCreateComplete 失败 : Waiter encountered a terminal failure state

php - AWS lambda函数:put event is not triggered in direct browser upload in php