Skip to content

Commit

Permalink
chore(app-staging-synthesizer): document and test `autoDeleteStagingA…
Browse files Browse the repository at this point in the history
…ssets: 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*
  • Loading branch information
kaizencc committed Jul 12, 2023
1 parent 05d875b commit 3e9dfb2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/@aws-cdk/app-staging-synthesizer-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,22 @@ const app = new App({
});
```

### Auto Delete Staging Assets on Deletion

By default, the staging resources will be cleaned up on stack deletion. That means that the
S3 Bucket and ECR Repositories are set to `RemovalPolicy.DESTROY` and have `autoDeleteObjects`
or `autoDeleteImages` turned on. This creates custom resources under the hood to facilitate
cleanup. To turn this off, specify `autoDeleteStagingAssets: false`.

```ts
const app = new App({
defaultStackSynthesizer: AppStagingSynthesizer.defaultResources({
appId: 'my-app-id',
autoDeleteStagingAssets: false,
}),
});
```

## Using a Custom Staging Stack per Environment

If you want to customize some behavior that is not configurable via properties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,36 @@ describe(AppStagingSynthesizer, () => {
});
});

test('auto delete assets can be turned off', () => {
// GIVEN
app = new App({
defaultStackSynthesizer: AppStagingSynthesizer.defaultResources({
appId: APP_ID,
autoDeleteStagingAssets: false,
}),
});
stack = new Stack(app, 'Stack', {
env: {
account: '000000000000',
region: 'us-east-1',
},
});

const assetName = 'abcdef';
stack.synthesizer.addDockerImageAsset({
directoryName: '.',
sourceHash: 'abcdef',
assetName,
});

// WHEN
const asm = app.synth();

// THEN
Template.fromJSON(getStagingResourceStack(asm).template).resourceCountIs('Custom::ECRAutoDeleteImages', 0);
Template.fromJSON(getStagingResourceStack(asm).template).resourceCountIs('Custom::S3AutoDeleteObjects', 0);
});

describe('environment specifics', () => {
test('throws if App includes env-agnostic and specific env stacks', () => {
// GIVEN - App with Stack with specific environment
Expand Down

0 comments on commit 3e9dfb2

Please sign in to comment.