Skip to content

Commit 69ea52f

Browse files
authored
fix(custom-resource-handler): auto-delete-[objects|images] breaks on cloudformation rollback (#29581)
### Issue # (if applicable) Closes #27199 ### Reason for this change Based on the way the custom resource is implemented, it is likely that unexpected behavior happens on Cloudformation rollback, i.e. the custom resource will prematurely delete the objects. Consider the following scenario: ``` UPDATE target resource (replacement, creates a new resource) UPDATE custom resource (old -> new, objects in old bucket are deleted) (...stuff happens...) ERROR, triggers a rollback UPDATE custom resource (new -> old) DELETE target resource (deletes the new resource, remembers the existing one) ``` We will have deleted objects in the bucket that has been rolled back to in this scenario, but the content is now gone. ### Description of changes Instead of deleting it right during update, we send back `PhysicalResourceId` in the event handler which if the id changes, it will let CFN to empty and delete the bucket at the end of the deployment. ### Description of how you validated changes New & updated tests. Also manually tested with deploying a template ``` const bucket = new s3.Bucket(this, 'Bucket', { removalPolicy: cdk.RemovalPolicy.DESTROY, bucketName: <a bucket name that's not used>, autoDeleteObjects: true, }); // Intentionally failure since `mybucket-1` exists const bucket2 = new s3.Bucket(this, 'Bucket2', { removalPolicy: cdk.RemovalPolicy.DESTROY, bucketName: <a bucket name that's not used>, }); bucket2.node.addDependency(bucket); ``` Once the deployment is successful, add some random content to the bucket, then update the code so that the first bucket's bucketName is updated to another valid name. Update the second bucket's bucketName to be an existing bucket name, which will trigger a deployment failure hence roll back. After the change, the content will stay there if a deployment failure happens. The content & bucket will be deleted if deployment is successful. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 91246ac commit 69ea52f

File tree

197 files changed

+102474
-73575
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

197 files changed

+102474
-73575
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-codepipeline-actions/test/cloudformation/integ.stacksets.js.snapshot/StackSetPipelineStack.assets.json

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-codepipeline-actions/test/cloudformation/integ.stacksets.js.snapshot/StackSetPipelineStack.template.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
"S3Bucket": {
114114
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
115115
},
116-
"S3Key": "54e6f07bf3aea46d100719f3b21fe0fb45ae789ee372d42d8cdfb97e21aba96c.zip"
116+
"S3Key": "96ea260348625427bb7f28ab3b379f62da6f428bcd155cb13f9261aa6a404b0d.zip"
117117
},
118118
"Timeout": 900,
119119
"MemorySize": 128,

packages/@aws-cdk-testing/framework-integ/test/aws-codepipeline-actions/test/cloudformation/integ.stacksets.js.snapshot/asset.54e6f07bf3aea46d100719f3b21fe0fb45ae789ee372d42d8cdfb97e21aba96c/index.js

-1
This file was deleted.

packages/@aws-cdk-testing/framework-integ/test/aws-codepipeline-actions/test/cloudformation/integ.stacksets.js.snapshot/asset.96ea260348625427bb7f28ab3b379f62da6f428bcd155cb13f9261aa6a404b0d/index.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-codepipeline-actions/test/cloudformation/integ.stacksets.js.snapshot/manifest.json

+7-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-codepipeline-actions/test/integ.pipeline-elastic-beanstalk-deploy.js.snapshot/aws-cdk-codepipeline-elastic-beanstalk-deploy.assets.json

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-codepipeline-actions/test/integ.pipeline-elastic-beanstalk-deploy.js.snapshot/aws-cdk-codepipeline-elastic-beanstalk-deploy.template.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
"S3Bucket": {
121121
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
122122
},
123-
"S3Key": "54e6f07bf3aea46d100719f3b21fe0fb45ae789ee372d42d8cdfb97e21aba96c.zip"
123+
"S3Key": "96ea260348625427bb7f28ab3b379f62da6f428bcd155cb13f9261aa6a404b0d.zip"
124124
},
125125
"Timeout": 900,
126126
"MemorySize": 128,
@@ -441,7 +441,7 @@
441441
"Value": "AWSServiceRoleForElasticBeanstalkManagedUpdates"
442442
}
443443
],
444-
"SolutionStackName": "64bit Amazon Linux 2023 v6.0.4 running Node.js 18"
444+
"SolutionStackName": "64bit Amazon Linux 2023 v6.1.2 running Node.js 20"
445445
},
446446
"DependsOn": [
447447
"beastalkapp",

packages/@aws-cdk-testing/framework-integ/test/aws-codepipeline-actions/test/integ.pipeline-elastic-beanstalk-deploy.js.snapshot/manifest.json

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-codepipeline-actions/test/integ.pipeline-elastic-beanstalk-deploy.js.snapshot/tree.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-codepipeline-actions/test/integ.pipeline-elastic-beanstalk-deploy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const beanstalkEnv = new elasticbeanstalk.CfnEnvironment(stack, 'beanstlk-env',
8383
applicationName: beanstalkApp.applicationName!,
8484
environmentName: 'codepipeline-test-env',
8585
// see https://docs.aws.amazon.com/elasticbeanstalk/latest/platforms/platforms-supported.html#platforms-supported.nodejs
86-
solutionStackName: '64bit Amazon Linux 2023 v6.0.4 running Node.js 18',
86+
solutionStackName: '64bit Amazon Linux 2023 v6.1.2 running Node.js 20',
8787
optionSettings: [
8888
{
8989
namespace: 'aws:autoscaling:launchconfiguration',
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)