Skip to content

Commit 2eb47ad

Browse files
authored
feat(aws-s3): orphan buckets by default (#1273)
Switch the default RemovalPolicy of a Bucket to Orphan. This reduces friction for users with stacks that contain Buckets. In the 99% of cases right now, any activity on a Bucket will cause the stack to fail to delete, and customers are left wondering how to fix this situation (see #1269 for example). It seems better to default to the frictionless case, and have people opt-in to hard deletes if they know for a fact the operation is going to work.
1 parent f5bc59b commit 2eb47ad

31 files changed

+112
-47
lines changed

packages/@aws-cdk/app-delivery/test/integ.cicd.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ const app = new cdk.App();
88

99
const stack = new cdk.Stack(app, 'CICD');
1010
const pipeline = new code.Pipeline(stack, 'CodePipeline', {
11-
artifactBucket: new s3.Bucket(stack, 'ArtifactBucket'),
11+
artifactBucket: new s3.Bucket(stack, 'ArtifactBucket', {
12+
removalPolicy: cdk.RemovalPolicy.Destroy
13+
})
1214
});
1315
const source = new code.GitHubSourceAction(stack, 'GitHub', {
1416
stage: pipeline.addStage('Source'),

packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-alias-target.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ const stack = new cdk.Stack(app, 'aws-cdk-cloudfront');
99

1010
const zone = new route53.PublicHostedZone(stack, 'HostedZone', { zoneName: 'test.public' });
1111

12-
const sourceBucket = new s3.Bucket(stack, 'Bucket');
12+
const sourceBucket = new s3.Bucket(stack, 'Bucket', {
13+
removalPolicy: cdk.RemovalPolicy.Destroy
14+
});
1315

1416
const distribution = new cloudfront.CloudFrontWebDistribution(stack, 'MyDistribution', {
1517
originConfigs: [

packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-bucket-logging.expected.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@
7070
}
7171
},
7272
"AnAmazingWebsiteProbably2LoggingBucket222F7CE9": {
73-
"Type": "AWS::S3::Bucket"
73+
"Type": "AWS::S3::Bucket",
74+
"DeletionPolicy": "Retain"
7475
},
7576
"AnAmazingWebsiteProbably2CFDistribution7C1CCD12": {
7677
"Type": "AWS::CloudFront::Distribution",
@@ -138,4 +139,4 @@
138139
}
139140
}
140141
}
141-
}
142+
}

packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-bucket-logging.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ const app = new cdk.App();
66

77
const stack = new cdk.Stack(app, 'aws-cdk-cloudfront-custom');
88

9-
const loggingBucket = new s3.Bucket(stack, 'Bucket');
9+
const loggingBucket = new s3.Bucket(stack, 'Bucket', {
10+
removalPolicy: cdk.RemovalPolicy.Destroy
11+
});
1012

1113
new cloudfront.CloudFrontWebDistribution(stack, 'AnAmazingWebsiteProbably', {
1214
originConfigs: [

packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-ipv6-disabled.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ const app = new cdk.App();
77

88
const stack = new cdk.Stack(app, 'aws-cdk-cloudfront');
99

10-
const sourceBucket = new s3.Bucket(stack, 'Bucket');
10+
const sourceBucket = new s3.Bucket(stack, 'Bucket', {
11+
removalPolicy: cdk.RemovalPolicy.Destroy
12+
});
1113

1214
new cloudfront.CloudFrontWebDistribution(stack, 'MyDistribution', {
1315
originConfigs: [

packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ const app = new cdk.App();
77

88
const stack = new cdk.Stack(app, 'aws-cdk-cloudfront');
99

10-
const sourceBucket = new s3.Bucket(stack, 'Bucket');
10+
const sourceBucket = new s3.Bucket(stack, 'Bucket', {
11+
removalPolicy: cdk.RemovalPolicy.Destroy
12+
});
1113

1214
new cloudfront.CloudFrontWebDistribution(stack, 'MyDistribution', {
1315
originConfigs: [

packages/@aws-cdk/aws-cloudfront/test/test.basic.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ export = {
117117
expect(stack).toMatch({
118118
"Resources": {
119119
"Bucket83908E77": {
120-
"Type": "AWS::S3::Bucket"
120+
"Type": "AWS::S3::Bucket",
121+
"DeletionPolicy": "Retain",
121122
},
122123
"AnAmazingWebsiteProbablyCFDistribution47E3983B": {
123124
"Type": "AWS::CloudFront::Distribution",
@@ -191,7 +192,8 @@ export = {
191192
expect(stack).toMatch({
192193
"Resources": {
193194
"Bucket83908E77": {
194-
"Type": "AWS::S3::Bucket"
195+
"Type": "AWS::S3::Bucket",
196+
"DeletionPolicy": "Retain",
195197
},
196198
"AnAmazingWebsiteProbablyCFDistribution47E3983B": {
197199
"Type": "AWS::CloudFront::Distribution",

packages/@aws-cdk/aws-codebuild/test/integ.caching.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ const app = new cdk.App();
77

88
const stack = new cdk.Stack(app, 'aws-cdk-codebuild');
99

10-
const bucket = new s3.Bucket(stack, 'CacheBucket');
10+
const bucket = new s3.Bucket(stack, 'CacheBucket', {
11+
removalPolicy: cdk.RemovalPolicy.Destroy
12+
});
1113

1214
new codebuild.Project(stack, 'MyProject', {
1315
cacheBucket: bucket,

packages/@aws-cdk/aws-codebuild/test/integ.project-bucket.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ const app = new cdk.App();
77

88
const stack = new cdk.Stack(app, 'aws-cdk-codebuild');
99

10-
const bucket = new s3.Bucket(stack, 'MyBucket');
10+
const bucket = new s3.Bucket(stack, 'MyBucket', {
11+
removalPolicy: cdk.RemovalPolicy.Destroy
12+
});
1113

1214
new codebuild.Project(stack, 'MyProject', {
1315
source: new codebuild.S3BucketSource({

packages/@aws-cdk/aws-codebuild/test/integ.project-secondary-sources-artifacts.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ const app = new cdk.App();
66

77
const stack = new cdk.Stack(app, 'aws-cdk-codebuild-secondary-sources-artifacts');
88

9-
const bucket = new s3.Bucket(stack, 'MyBucket');
9+
const bucket = new s3.Bucket(stack, 'MyBucket', {
10+
removalPolicy: cdk.RemovalPolicy.Destroy
11+
});
1012

1113
new codebuild.Project(stack, 'MyProject', {
1214
buildSpec: {

0 commit comments

Comments
 (0)