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

时间:2018-12-19 10:19:38

标签: amazon-s3 amazon-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

代码与通知块一起使用。 但是上面的模板不适用于通知。

出现以下错误:

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

我能够从控制台上完成。

有人帮助我解决此问题吗?

2 个答案:

答案 0 :(得分:1)

这太迟了,所以更多地回答这个问题(只是设法解决了同样的问题):由于对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

答案 1 :(得分:0)

尝试获取.gz并仅放入gz。