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

chore(app-staging-synthesizer): document and test autoDeleteStagingAssets: false #26321

Merged
merged 6 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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