Skip to content

Commit 3e9dfb2

Browse files
authored
chore(app-staging-synthesizer): document and test autoDeleteStagingAssets: false (#26321)
The motivation here is that I went to add this option and realized that it already existed. However, setting the property to `false` wasn't tested or documented. This PR does both of those things. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 05d875b commit 3e9dfb2

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

packages/@aws-cdk/app-staging-synthesizer-alpha/README.md

+16
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,22 @@ const app = new App({
249249
});
250250
```
251251

252+
### Auto Delete Staging Assets on Deletion
253+
254+
By default, the staging resources will be cleaned up on stack deletion. That means that the
255+
S3 Bucket and ECR Repositories are set to `RemovalPolicy.DESTROY` and have `autoDeleteObjects`
256+
or `autoDeleteImages` turned on. This creates custom resources under the hood to facilitate
257+
cleanup. To turn this off, specify `autoDeleteStagingAssets: false`.
258+
259+
```ts
260+
const app = new App({
261+
defaultStackSynthesizer: AppStagingSynthesizer.defaultResources({
262+
appId: 'my-app-id',
263+
autoDeleteStagingAssets: false,
264+
}),
265+
});
266+
```
267+
252268
## Using a Custom Staging Stack per Environment
253269

254270
If you want to customize some behavior that is not configurable via properties,

packages/@aws-cdk/app-staging-synthesizer-alpha/test/app-staging-synthesizer.test.ts

+30
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,36 @@ describe(AppStagingSynthesizer, () => {
462462
});
463463
});
464464

465+
test('auto delete assets can be turned off', () => {
466+
// GIVEN
467+
app = new App({
468+
defaultStackSynthesizer: AppStagingSynthesizer.defaultResources({
469+
appId: APP_ID,
470+
autoDeleteStagingAssets: false,
471+
}),
472+
});
473+
stack = new Stack(app, 'Stack', {
474+
env: {
475+
account: '000000000000',
476+
region: 'us-east-1',
477+
},
478+
});
479+
480+
const assetName = 'abcdef';
481+
stack.synthesizer.addDockerImageAsset({
482+
directoryName: '.',
483+
sourceHash: 'abcdef',
484+
assetName,
485+
});
486+
487+
// WHEN
488+
const asm = app.synth();
489+
490+
// THEN
491+
Template.fromJSON(getStagingResourceStack(asm).template).resourceCountIs('Custom::ECRAutoDeleteImages', 0);
492+
Template.fromJSON(getStagingResourceStack(asm).template).resourceCountIs('Custom::S3AutoDeleteObjects', 0);
493+
});
494+
465495
describe('environment specifics', () => {
466496
test('throws if App includes env-agnostic and specific env stacks', () => {
467497
// GIVEN - App with Stack with specific environment

0 commit comments

Comments
 (0)