How to implement S3 replication for existing objects in CDK?

  1. I already can replicate existing objects from aws console by setting up a batch job.

  2. But how to do the same thing in CDK?

  3. Currently, in CDK, I can only implement live replication for a new created bucket, not for existing objects. Here is

// create a new bucket and add replication rule 
// How to do replication for an existed bucket? 
const source = new cdk.aws_s3.CfnBucket(this, "SourceBucketNew", {
      bucketName: `replication-source-bucket-${this.account}`,
      versioningConfiguration: {
        status: "Enabled",
      replicationConfiguration: {
        role: role.roleArn,
        rules: [
            destination: {
              bucket: dest.bucketArn,
            status: "Enabled",
asked 3 months ago29 views
1 Answer

If you did not create the bucket with the CDK app, it is not possible to change the replication without a direct API call outside of CloudFormation. You would need to make that change using an AWSCustomResource.

There is a bit more context as to why this is the case here:

profile picture
answered 3 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions