如何在S3中修复“必须指定TransitionDate和TransitionInDays之一”

时间:2019-07-08 21:17:00

标签: amazon-s3 amazon-cloudformation

当我要通过Cloudformation堆栈创建S3存储桶时,它向我发送此错误消息:“必须指定TransitionDate和TransitionInDays中的一个。” 按照以下代码指定以天为单位的过渡:

Resources:
  S3CreateBucket:
    Type: AWS::S3::Bucket
    Properties:
          BucketName: !Sub "${AWS::StackName}"

          BucketEncryption:
            ServerSideEncryptionConfiguration:
              - ServerSideEncryptionByDefault:
                  SSEAlgorithm: AES256
          LoggingConfiguration:
            DestinationBucketName: xxxx
            LogFilePrefix: !Sub "{AWS::StackName}"/                      
          LifecycleConfiguration:
            Rules:
              - Id: Multipartupload
                Status: 'Enabled'
                AbortIncompleteMultipartUpload:
                  DaysAfterInitiation: 7 
                ExpirationInDays: 180                     
              -  Id: Glacier
                 Status: 'Enabled'
                 Transitions:                  
                  - StorageClass: GLACIER
                  - TransitionInDays: 90            
          Tags:
            -
             Key: Name
             Value: public
          VersioningConfiguration:
            Status: Enabled
          WebsiteConfiguration:
            ErrorDocument: error.html
            IndexDocument: index.html


该如何解决此问题?

1 个答案:

答案 0 :(得分:0)

我认为您在“转换”部分的格式不正确。我相信这会起作用:

  S3CreateBucket:
    Type: AWS::S3::Bucket
    Properties:
          BucketName: !Sub "${AWS::StackName}"

          BucketEncryption:
            ServerSideEncryptionConfiguration:
              - ServerSideEncryptionByDefault:
                  SSEAlgorithm: AES256
          LoggingConfiguration:
            DestinationBucketName: xxxx
            LogFilePrefix: !Sub "{AWS::StackName}"/                      
          LifecycleConfiguration:
            Rules:
              - Id: Multipartupload
                Status: 'Enabled'
                AbortIncompleteMultipartUpload:
                  DaysAfterInitiation: 7 
                ExpirationInDays: 180                     
              -  Id: Glacier
                 Status: 'Enabled'
                 Transition:                  
                   StorageClass: GLACIER
                   TransitionInDays: 90            
          Tags:
            -
             Key: Name
             Value: public
          VersioningConfiguration:
            Status: Enabled
          WebsiteConfiguration:
            ErrorDocument: error.html
            IndexDocument: index.html

请注意,我已将“过渡”更改为“过渡”,并删除了2个单独的列表 https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket-lifecycleconfig-rule-transition.html

如果您打算在计划添加多个过渡时使用过渡,则可以执行以下操作:

    Transitions:
      - StorageClass: String
        TransitionDate: Timestamp
        TransitionInDays: Integer
      - StorageClass: String
        TransitionDate: Timestamp
        TransitionInDays: Integer