LoginSignup
2
0

More than 3 years have passed since last update.

【AWS CloudFormation】「レプリケーション時間のコントロール (RTC)」等を含めたS3レプリケーション設定のテンプレートの書き方

Last updated at Posted at 2021-02-27

前置き

現場で AWS の CloudFormation に初挑戦することになりました。
「レプリケーション時間のコントロール (RTC)」等を含めた、
S3レプリケーション設定のテンプレートの書き方で引っかかったことがあったので、投稿します。

内容

以下のようなテンプレートファイルでスタックを作成し、実行しました。

S3BucketOriginal:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: !Sub 'original-${AWS::AccountId}'
      VersioningConfiguration:
        Status: Enabled
      ReplicationConfiguration:
        Role: !Sub 'arn:aws:iam::${AWS::AccountId}:role/OriginBucketBackupRole'
        Rules:
        - Id: BackUpRule
          Status: Enabled
          DeleteMarkerReplication:
            Status: Disabled
          Destination:
            Bucket: !Sub 'arn:aws:s3:::backup-${AWS::AccountId}'
            EncryptionConfiguration:
              ReplicaKmsKeyID: !Sub 'arn:aws:kms:${AWS::Region}:${AWS::AccountId}:alias/BackupKey'
            Metrics: 
              Status: Enabled
              EventThreshold: 
                Minutes: 15
            ReplicationTime:
              Status: Enabled
              Time:
                Minutes: 15
          SourceSelectionCriteria: 
            SseKmsEncryptedObjects:
              Status: Enabled

すると、以下のようなエラーになってしまいました。

DeleteMarkerReplication cannot be used for this version of Cross Region Replication configuration schema.
Please refer to S3 Developer Guide for more information

このエラーは、以下CloudFormationのユーザーガイド「ReplicationRule」内の注記のとおりです。

前述のエラーメッセージ内のthis versionは、S3のレプリケーション設定のバージョンのことでした。

スクリーンショット 2021-02-28 6.25.49.png

以下のように、Filter を設定しないとS3のレプリケーション設定はV1になってしまうということでした。

・・・
      ReplicationConfiguration:
        Role: !Sub 'arn:aws:iam::${AWS::AccountId}:role/OriginBucketBackupRole'
        Rules:
        - Id: BackUpRule
          Status: Enabled
          DeleteMarkerReplication:
             Status: Disabled
          Filter:         # 追加
            Prefix: ""    # 追加
・・・

Filter を設定していないと、以下のように Replication Time Control (S3 RTC) の設定もエラーとなってしまいます。

ReplicationTime cannot be used for this version of the replication configuration schema.
Please refer to S3 Developer Guide for more information

Filter を設定したテンプレートでスタックを実行して今度こそ・・・
と思ったら以下のようなエラーになってしまいました。

Priority must be specified for this version of Cross Region Replication configuration schema.
Please refer to the S3 Developer Guide for more information

Priority(優先度)は、 CloudFormation のユーザーガイドでは「必須:いいえ」となっているのに・・・

スクリーンショット 2021-02-28 6.27.47.png

マネジメントコンソールからの設定だと、自動に設定してくれていれるんですね・・・
全く意識したことなかったです・・・

スクリーンショット 2021-02-28 6.52.27.png

その他にも、レプリケーション時間のコントロール (RTC)等の設定はマネジメントコンソール上だとチェックボックスでONにするだけなのですが、
CloudFormationのテンプレートでは時間数が必須入力する必要があります。
このあたり、マネジメントコンソールでは意識しないので難しい・・・

スクリーンショット 2021-02-28 6.54.54.png

            Metrics: 
              Status: Enabled
              EventThreshold: 
                Minutes: 15
            ReplicationTime:
              Status: Enabled
              Time:
                Minutes: 15

結果

最終的にはテンプレートファイルを以下のようにすることで、レプリケーション設定を作成することが出来ました。
(BucketName、ReplicaKmsKeyID 辺りの指定方法は適宜置き換えください)

Resources:
  S3BucketOriginal:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: !Sub 'original-${AWS::AccountId}'
      VersioningConfiguration:
        Status: Enabled
      ReplicationConfiguration:
        Role: !Sub 'arn:aws:iam::${AWS::AccountId}:role/OriginBucketBackupRole'
        Rules:
        - Id: BackUpRule
          Status: Enabled
          DeleteMarkerReplication:
             Status: Disabled
          Filter:       #追加
            Prefix: ""  #追加
          Priority: 0   #追加
          Destination:
            Bucket: !Sub 'arn:aws:s3:::backup-${AWS::AccountId}'
            EncryptionConfiguration:
              ReplicaKmsKeyID: !Sub 'arn:aws:kms:${AWS::Region}:${AWS::AccountId}:alias/BackupKey'
            Metrics: 
              Status: Enabled
              EventThreshold: 
                Minutes: 15
            ReplicationTime:
              Status: Enabled
              Time:
                Minutes: 15
          SourceSelectionCriteria: 
            SseKmsEncryptedObjects:
              Status: Enabled
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0