Introduction#
- Replication for new created buckets
- Replication for existing objects
- Batch operation introuction
1. For New Buckets#
const dest = new cdk.aws_s3.Bucket(this,"DestBucket",{bucketName: `dest-bucket-${this.account}`,versioned: true,removalPolicy: RemovalPolicy.DESTROY})
role for replication rule
const role = new cdk.aws_iam.Role(this,"RoleForReplicationTask",{roleName: "RoleForReplicationTask",assumedBy: new cdk.aws_iam.ServicePrincipal("s3.amazonaws.com"),inlinePolicies: {"AllowCopyData": new cdk.aws_iam.PolicyDocument({statements: [// my lazy role - check docs for least privildgenew cdk.aws_iam.PolicyStatement({effect: Effect.ALLOW,resources: ["*"],actions: ["s3:*"]})]})}})
source bucket
const source = new cdk.aws_s3.CfnBucket(this,"SourceBucket",{bucketName: `source-bucket-${this.account}`,versioningConfiguration: {status: "Enabled",},// replication configuration and rulesreplicationConfiguration: {role: role.roleArn,rules: [{status: "Enabled",// prefix: "images/",destination: {bucket: dest.bucketArn}}]}})
2. For Existing Objects#
Need to create a batch job from aws console. Note to
- Provide the correct roles for replication rule and batch job
- It is good to choose create roles option so the role is automatically created