Search code examples
pythonamazon-s3replicationaws-cdk

AWS S3 CDK Python Bucket replication configuration


I'm using CDK python to create and S3 bucket and a replication.configuration across a region

I keep getting an error when I synth:

Value did not match any type in union

here is my code for the rules section of my s3.CfnBucket.ReplicationConfigurationProperty:

Can someone check out my code for the source selection area. I think that is where the issue is:

        self.replication_conf = s3.CfnBucket.ReplicationConfigurationProperty(
            role=new_role_arn,
            rules=[
                s3.CfnBucket.ReplicationRuleProperty(
                    id='replicate-all-rule',
                    destination=some_arn,
                    status='Enabled',
                    source_selection_criteria = s3.CfnBucket.SseKmsEncryptedObjectsProperty(
                       status='Enabled'
                    )
                )         
            ]
        )

Solution

  • It seems that your syntax is simply incorrect.

    According to the documentation the source_selection_criteria should be of type SourceSelectionCriteriaProperty. It is that property that holds the SseKmsEncryptedObjectsProperty. Presumably this is correct (although it is untested):

    self.replication_conf = s3.CfnBucket.ReplicationConfigurationProperty(
      role=new_role_arn,
      rules=[
        s3.CfnBucket.ReplicationRuleProperty(
          id='replicate-all-rule',
          destination=some_arn,
          status='Enabled',
          source_selection_criteria=s3.CfnBucket.SourceSelectionCriteriaProperty(
            sse_kms_encrypted_objects=s3.CfnBucket.SseKmsEncryptedObjectsProperty(
                status='Enabled'
              )
            )
        )
      ]
    )