-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
aws-s3: RemovalPolicy.RETAIN not functioning properly in CDK v2 #26276
Comments
I figured out that I was using some custom built property on top of my CDK stack. And that was not allowing me to override the default value of RemovalPolicy. Sorry for the trouble there but yes it's working fine from CDK v2 perspective. Thanks for the help! |
|
Describe the bug
I am using CDK v2 with Typescript to create a S3 bucket. I want the bucket to be orphaned from the stack and retain it even if the stack gets deleted. For that, I am trying to use one of the property of BucketProps that is RemovalPolicy. By default its value is DESTROY and if I override that to RETAIN, it doesn't execute this change and still I'm getting DESTROY as its value.
It is working fine in CDK v1, but after migrating to v2, the RemovalPolicy property is not accepting any override values.
Expected Behavior
In CDK v1 --
this.myBucket = new Bucket(this, "my-bucket-name", {
bucketName: "my-bucket-name",
blockPublicAccess: {
blockPublicAcls: true,
blockPublicPolicy: true,
ignorePublicAcls: true,
restrictPublicBuckets: true
},
versioned: false,
removalPolicy: RemovalPolicy.RETAIN
});
After building the stack, its corresponding JSON template gives the output --
"BucketName": "my-bucket-name",
"PublicAccessBlockConfiguration": {
"BlockPublicAcls": true,
"BlockPublicPolicy": true,
"IgnorePublicAcls": true,
"RestrictPublicBuckets": true
}
},
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain",
It overrides the default value of DESTROY and sets the DeletionPolicy as "Retain" correctly in its JSON. But this doesn't happen in case of CDK v2.
Current Behavior
In CDK v2 --
this.myBucket = new Bucket(this, "my-bucket-name", {
bucketName: "my-bucket-name",
blockPublicAccess: {
blockPublicAcls: true,
blockPublicPolicy: true,
ignorePublicAcls: true,
restrictPublicBuckets: true
},
versioned: false,
removalPolicy: RemovalPolicy.RETAIN
});
After building the stack, its corresponding JSON template gives the output --
"BucketName": "my-bucket-name",
"PublicAccessBlockConfiguration": {
"BlockPublicAcls": true,
"BlockPublicPolicy": true,
"IgnorePublicAcls": true,
"RestrictPublicBuckets": true
}
},
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete",
Even after setting the RemovalPolicy property to RETAIN, its corresponding JSON template has the value of "Delete".
Reproduction Steps
Code snippet --
this.myBucket = new Bucket(this, "my-bucket-name", {
bucketName: "my-bucket-name",
blockPublicAccess: {
blockPublicAcls: true,
blockPublicPolicy: true,
ignorePublicAcls: true,
restrictPublicBuckets: true
},
versioned: false,
removalPolicy: RemovalPolicy.RETAIN
});
After building the stack, check for its JSON file to see what are the values of each property.
Possible Solution
Allowing override to the default value that has been set for the RemovalPolicy property of BucketProps
Additional Information/Context
CDK v2 documentation has mentioned the values for RemovalPolicy- RETAIN, DESTROY etc.
(https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.Bucket.html)
(https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.RemovalPolicy.html)
CDK CLI Version
2.55.1
Framework Version
No response
Node.js Version
18.16.0
OS
macOS/Linux
Language
Typescript
Language Version
TypeScript (4.9.5)
Other information
No response
The text was updated successfully, but these errors were encountered: