Skip to content
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

Closed
SehajveerSingh opened this issue Jul 7, 2023 · 3 comments
Closed
Labels
@aws-cdk/aws-s3 Related to Amazon S3 bug This issue is a bug. effort/medium Medium work item – several days of effort p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@SehajveerSingh
Copy link

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

@SehajveerSingh SehajveerSingh added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 7, 2023
@github-actions github-actions bot added the @aws-cdk/aws-s3 Related to Amazon S3 label Jul 7, 2023
@pahud pahud self-assigned this Jul 7, 2023
@pahud
Copy link
Contributor

pahud commented Jul 7, 2023

image

It works for me in cdk 2.83.1 as we as 2.55.1.

Can you check the cdk synth output again?

@pahud pahud added p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. effort/medium Medium work item – several days of effort labels Jul 7, 2023
@pahud pahud removed their assignment Jul 7, 2023
@pahud pahud removed the needs-triage This issue or PR still needs to be triaged. label Jul 7, 2023
@SehajveerSingh
Copy link
Author

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!

@github-actions
Copy link

github-actions bot commented Jul 8, 2023

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-s3 Related to Amazon S3 bug This issue is a bug. effort/medium Medium work item – several days of effort p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants