Skip to content

Commit 9364e94

Browse files
feat(cli-lib): support bootstrap command (#26205)
The first iteration of [@aws-cdk/cli-lib-alpha](https://docs.aws.amazon.com/cdk/api/v2/docs/cli-lib-alpha-readme.html) doesn't support the bootstrap command that is mandatory to deploy a new app via CDK. This PR introduces the bootstrap command for the CLI. Related: #15851 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent db923dd commit 9364e94

File tree

5 files changed

+178
-1
lines changed

5 files changed

+178
-1
lines changed

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

+8
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Currently the package includes implementations for:
3434

3535
- `cdk deploy`
3636
- `cdk synth`
37+
- `cdk bootstrap`
3738
- `cdk destroy`
3839
- `cdk list`
3940

@@ -95,6 +96,13 @@ cli.synth({
9596
});
9697
```
9798

99+
### bootstrap
100+
101+
```ts
102+
// await this asynchronous method call using a language feature
103+
cli.bootstrap();
104+
```
105+
98106
### deploy
99107

100108
```ts

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

+34-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { exec as runCli } from 'aws-cdk/lib';
33
// eslint-disable-next-line import/no-extraneous-dependencies
44
import { createAssembly, prepareContext, prepareDefaultEnvironment } from 'aws-cdk/lib/api/cxapp/exec';
5-
import { SharedOptions, DeployOptions, DestroyOptions, SynthOptions, ListOptions, StackActivityProgress } from './commands';
5+
import { SharedOptions, DeployOptions, DestroyOptions, BootstrapOptions, SynthOptions, ListOptions, StackActivityProgress } from './commands';
66

77
/**
88
* AWS CDK CLI operations
@@ -18,6 +18,11 @@ export interface IAwsCdkCli {
1818
*/
1919
synth(options?: SynthOptions): Promise<void>;
2020

21+
/**
22+
* cdk bootstrap
23+
*/
24+
bootstrap(options?: BootstrapOptions): Promise<void>;
25+
2126
/**
2227
* cdk deploy
2328
*/
@@ -163,6 +168,34 @@ export class AwsCdkCli implements IAwsCdkCli {
163168
await this.exec(['synth', ...synthCommandArgs]);
164169
}
165170

171+
/**
172+
* cdk bootstrap
173+
*/
174+
public async bootstrap(options: BootstrapOptions = {}) {
175+
const bootstrapCommandArgs: string[] = [
176+
...renderBooleanArg('force', options.force),
177+
...renderBooleanArg('show-template', options.showTemplate),
178+
...renderBooleanArg('terminationProtection', options.terminationProtection),
179+
...renderBooleanArg('example-permissions-boundary', options.examplePermissionsBoundary),
180+
...renderBooleanArg('terminationProtection', options.usePreviousParameters),
181+
...renderBooleanArg('execute', options.execute),
182+
...options.toolkitStackName ? ['--toolkit-stack-name', options.toolkitStackName] : [],
183+
...options.bootstrapBucketName ? ['--bootstrap-bucket-name', options.bootstrapBucketName] : [],
184+
...options.cfnExecutionPolicy ? ['--cloudformation-execution-policies', options.cfnExecutionPolicy] : [],
185+
...options.template ? ['--template', options.template] : [],
186+
...options.customPermissionsBoundary ? ['--custom-permissions-boundary', options.customPermissionsBoundary] : [],
187+
...options.qualifier ? ['--qualifier', options.qualifier] : [],
188+
...options.trust ? ['--qualifier', options.trust] : [],
189+
...options.trustForLookup ? ['--qualifier', options.trustForLookup] : [],
190+
...options.bootstrapKmsKeyId ? ['--bootstrap-kms-key-id', options.bootstrapKmsKeyId] : [],
191+
...options.bootstrapCustomerKey ? ['--bootstrap-customer-key', options.bootstrapCustomerKey] : [],
192+
...options.publicAccessBlockConfiguration ? ['--public-access-block-configuration', options.publicAccessBlockConfiguration] : [],
193+
...this.createDefaultArguments(options),
194+
];
195+
196+
await this.exec(['bootstrap', ...bootstrapCommandArgs]);
197+
}
198+
166199
/**
167200
* cdk deploy
168201
*/
+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import { SharedOptions } from './common';
2+
3+
/**
4+
* Options to use with cdk bootstrap
5+
*/
6+
export interface BootstrapOptions extends SharedOptions {
7+
8+
/**
9+
* The name of the CDK toolkit stack to create
10+
*/
11+
readonly toolkitStackName?: string;
12+
13+
/**
14+
* The name of the CDK toolkit bucket; bucket will be created and
15+
* must not exist
16+
* @default - auto-generated CloudFormation name
17+
*/
18+
readonly bootstrapBucketName?: string;
19+
20+
/**
21+
* Always bootstrap even if it would downgrade template version
22+
* @default false
23+
*/
24+
readonly force?: boolean;
25+
26+
/**
27+
* The Managed Policy ARNs that should be attached to the
28+
* role performing deployments into this environment (may be repeated, modern bootstrapping only)
29+
* @default - none
30+
*/
31+
readonly cfnExecutionPolicy?: string;
32+
33+
/**
34+
* Instead of actual bootstrapping, print the current
35+
* CLI\'s bootstrapping template to stdout for customization
36+
* @default false
37+
*/
38+
readonly showTemplate?: boolean;
39+
40+
/**
41+
* Use the template from the given file instead of the
42+
* built-in one (use --show-template to obtain an example)
43+
*/
44+
readonly template?: string;
45+
46+
/**
47+
* Toggle CloudFormation termination protection on the
48+
* bootstrap stacks
49+
* @default false
50+
*/
51+
readonly terminationProtection?: boolean;
52+
53+
/**
54+
* Use the example permissions boundary.
55+
* @default undefined
56+
*/
57+
readonly examplePermissionsBoundary?: boolean;
58+
59+
/**
60+
* Use the permissions boundary specified by name.
61+
* @default undefined
62+
*/
63+
readonly customPermissionsBoundary?: string;
64+
65+
/**
66+
* Use previous values for existing parameters (you must specify
67+
* all parameters on every deployment if this is disabled)
68+
* @default true
69+
*/
70+
readonly usePreviousParameters?: boolean;
71+
72+
/**
73+
* Whether to execute ChangeSet (--no-execute will NOT execute
74+
* the ChangeSet)
75+
* @default true
76+
*/
77+
readonly execute?: boolean;
78+
79+
/**
80+
* String which must be unique for each bootstrap stack. You
81+
* must configure it on your CDK app if you change this
82+
* from the default.
83+
* @default undefined
84+
*/
85+
readonly qualifier?: string;
86+
87+
/**
88+
* The AWS account IDs that should be trusted to perform
89+
* deployments into this environment (may be repeated,
90+
* modern bootstrapping only)
91+
* @default undefined
92+
*/
93+
readonly trust?: string;
94+
95+
/**
96+
* The AWS account IDs that should be trusted to look
97+
* up values in this environment (may be repeated,
98+
* modern bootstrapping only)
99+
* @default undefined
100+
*/
101+
readonly trustForLookup?: string;
102+
103+
/**
104+
* AWS KMS master key ID used for the SSE-KMS encryption
105+
* @default undefined
106+
*/
107+
readonly bootstrapKmsKeyId?: string;
108+
109+
/**
110+
* Create a Customer Master Key (CMK) for the bootstrap
111+
* bucket (you will be charged but can customize
112+
* permissions, modern bootstrapping only)
113+
* @default undefined
114+
*/
115+
readonly bootstrapCustomerKey?: string;
116+
117+
/**
118+
* Block public access configuration on CDK toolkit
119+
* bucket (enabled by default)
120+
* @default undefined
121+
*/
122+
readonly publicAccessBlockConfiguration?: string;
123+
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * from './deploy';
33
export * from './destroy';
44
export * from './list';
55
export * from './synth';
6+
export * from './bootstrap';

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

+12
Original file line numberDiff line numberDiff line change
@@ -318,4 +318,16 @@ describe('list', () => {
318318
expect.anything(),
319319
);
320320
});
321+
322+
test('bootstrap without options', async () => {
323+
// WHEN
324+
await cdk.bootstrap();
325+
326+
// THEN
327+
expect(jest.mocked(cli.exec)).toHaveBeenCalledWith(
328+
['bootstrap', '--all'],
329+
expect.anything(),
330+
);
331+
});
332+
321333
});

0 commit comments

Comments
 (0)