question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[s3] Add replication configuration to existing S3 bucket

See original GitHub issue

❓ General Issue

The Question

I’m trying to assign replication configuration to existing S3 bucket using the code:

const cfnBucket = bucket.node.defaultChild as s3.CfnBucket;

    cfnBucket.replicationConfiguration = {
      role: replicationRole.roleName,
      rules:[
        {
          destination:{
            bucket: bucket.bucketName
          },
          prefix: "target_prefix",
          status: "Enabled",
          filter: {
            prefix: "source_prefix"
          }
        }
      ]
    }

Getting error at cdk synth: Cannot set property ‘replicationConfiguration’ of undefined

If I create bucket from the CDK code - template synth is working fine.

Is there any workaround to do the trick?

Environment

  • CDK CLI Version: 1.63.0 (build 7a68125)
  • Module Version:
  • Node.js Version: v14.8.0
  • OS: OSX 10.14.6
  • Language (Version): TypeScript

Other information

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
iliapolocommented, Sep 15, 2020

@SZubarev You can set it up just like you did, but not on an imported bucket. That is, if you create your bucket inside the same cdk app:

const bucket = new s3.Bucket(this, 'Bucket)

Then you use the escape hatch just like you did.

If you need to setup replication configuration on an already existing bucket, you’d need to use the AwsCustomResource and invoke the appropriate API call using the AWS JavaScript SDK.

A separate CFN template will also not help because you won’t be able to include an existing bucket into a CFN template (this is also why CDK doesn’t support it).

0reactions
SomayaBcommented, Sep 30, 2020

Closing this issue since it seems to be resolved. Feel free to reopen.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring replication for source and destination buckets ...
Set up replication in Amazon S3 where the source and destination buckets are owned by the same AWS account.
Read more >
How to add a replication rule to an S3 bucket - HowtoForge
Replication can copy newly created or updated objects from the source S3 bucket to the destination S3 bucket. The objects which already exist...
Read more >
How to easily replicate existing S3 objects using S3 batch ...
Click on the bucket that you just created and navigate to the management tab. For creating S3 batch replication, we first have to...
Read more >
Replicating objects - Amazon Simple Storage Service
Replication enables automatic, asynchronous copying of objects across Amazon S3 buckets. Buckets that are configured for object replication can be owned by the ......
Read more >
Is there a way to add s3 replication policy with existing bucket ...
I don't think you can. CDK code converts into CloudFormation. An AWS::S3::Bucket entity contains a ReplicationConfiguration .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found