Skip to content

Commit fec4bb1

Browse files
authored
fix(cli-lib): cannot bootstrap specific environment (#31713)
### Issue Closes #31656 ### Reason for this change When boostrapping, users may need to explicitly provide the environment if it can be determined from the app or shell environment. Previously this was not possible using the cli-lib-alpha package. ### Description of changes Add a new argument to support environments. ### Description of how you validated changes Unit test case was added. ### 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 d80e3cd commit fec4bb1

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

Diff for: packages/@aws-cdk/cli-lib-alpha/lib/cli.ts

+2
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ export class AwsCdkCli implements IAwsCdkCli {
172172
* cdk bootstrap
173173
*/
174174
public async bootstrap(options: BootstrapOptions = {}) {
175+
const envs = options.environments ?? [];
175176
const bootstrapCommandArgs: string[] = [
177+
...envs,
176178
...renderBooleanArg('force', options.force),
177179
...renderBooleanArg('show-template', options.showTemplate),
178180
...renderBooleanArg('terminationProtection', options.terminationProtection),

Diff for: packages/@aws-cdk/cli-lib-alpha/lib/commands/bootstrap.ts

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ import { SharedOptions } from './common';
44
* Options to use with cdk bootstrap
55
*/
66
export interface BootstrapOptions extends SharedOptions {
7+
/**
8+
* The target AWS environments to deploy the bootstrap stack to.
9+
* Uses the following format: `aws://<account-id>/<region>`
10+
*
11+
* @example "aws://123456789012/us-east-1"
12+
* @default - Bootstrap all environments referenced in the CDK app or determine an environment from local configuration.
13+
*/
14+
readonly environments?: string[];
715

816
/**
917
* The name of the CDK toolkit stack to create

Diff for: packages/@aws-cdk/cli-lib-alpha/test/commands.test.ts

+12
Original file line numberDiff line numberDiff line change
@@ -369,4 +369,16 @@ describe('list', () => {
369369
);
370370
});
371371

372+
test('bootstrap specific environment', async () => {
373+
// WHEN
374+
await cdk.bootstrap({
375+
environments: ['aws://123456789012/us-east-1'],
376+
});
377+
378+
// THEN
379+
expect(jest.mocked(cli.exec)).toHaveBeenCalledWith(
380+
['bootstrap', 'aws://123456789012/us-east-1', '--all'],
381+
expect.anything(),
382+
);
383+
});
372384
});

0 commit comments

Comments
 (0)