Skip to content

Commit 3bfc641

Browse files
orangewiserix0rrr
authored andcommitted
feat(bootstrap): allow specifying the toolkit staging bucket name (#2407)
Add a command line argument to specify the toolkit staging bucket name. Closes #2390.
1 parent 433e144 commit 3bfc641

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

packages/aws-cdk/README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,12 @@ configuration's order of precedence is:
164164
Some of the interesting keys that can be used in the JSON configuration files:
165165
```js
166166
{
167-
"app": "node bin/main.js", // Command to start the CDK app (--app='node bin/main.js')
168-
"context": { // Context entries (--context=key=value)
167+
"app": "node bin/main.js", // Command to start the CDK app (--app='node bin/main.js')
168+
"context": { // Context entries (--context=key=value)
169169
"key": "value",
170170
},
171-
"toolkitStackName": "foo", // Customize 'bootstrap' stack name (--toolkit-stack-name=foo)
172-
"versionReporting": false, // Opt-out of version reporting (--no-version-reporting)
171+
"toolkitStackName": "foo", // Customize 'bootstrap' stack name (--toolkit-stack-name=foo)
172+
"toolkitBucketName": "fooBucket", // Customize 'bootstrap' bucket name(--toolkit-bucket-name=fooBucket)
173+
"versionReporting": false, // Opt-out of version reporting (--no-version-reporting)
173174
}
174175
```

packages/aws-cdk/bin/cdk.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ async function parseCommandLineArguments() {
5656
.option('interactive', { type: 'boolean', alias: 'i', desc: 'interactively watch and show template updates' })
5757
.option('output', { type: 'string', alias: 'o', desc: 'write CloudFormation template for requested stacks to the given directory', requiresArg: true })
5858
.option('numbered', { type: 'boolean', alias: 'n', desc: 'prefix filenames with numbers to indicate deployment ordering' }))
59-
.command('bootstrap [ENVIRONMENTS..]', 'Deploys the CDK toolkit stack into an AWS environment')
59+
.command('bootstrap [ENVIRONMENTS..]', 'Deploys the CDK toolkit stack into an AWS environment', yargs => yargs
60+
.option('toolkit-bucket-name', { type: 'string', alias: 'b', desc: 'The name of the CDK toolkit bucket', default: undefined }))
6061
.command('deploy [STACKS..]', 'Deploys the stack(s) named STACKS into your AWS account', yargs => yargs
6162
.option('build-exclude', { type: 'array', alias: 'E', nargs: 1, desc: 'do not rebuild asset with the given ID. Can be specified multiple times.', default: [] })
6263
.option('exclusively', { type: 'boolean', alias: 'e', desc: 'only deploy requested stacks, don\'t include dependencies' })
@@ -189,7 +190,7 @@ async function initCommandLine() {
189190
});
190191

191192
case 'bootstrap':
192-
return await cliBootstrap(args.ENVIRONMENTS, toolkitStackName, args.roleArn);
193+
return await cliBootstrap(args.ENVIRONMENTS, toolkitStackName, args.roleArn, args.toolkitBucketName);
193194

194195
case 'deploy':
195196
return await cli.deploy({
@@ -238,7 +239,7 @@ async function initCommandLine() {
238239
* all stacks are implicitly selected.
239240
* @param toolkitStackName the name to be used for the CDK Toolkit stack.
240241
*/
241-
async function cliBootstrap(environmentGlobs: string[], toolkitStackName: string, roleArn: string | undefined): Promise<void> {
242+
async function cliBootstrap(environmentGlobs: string[], toolkitStackName: string, roleArn: string | undefined, toolkitBucketName: string | undefined): Promise<void> {
242243
// Two modes of operation.
243244
//
244245
// If there is an '--app' argument, we select the environments from the app. Otherwise we just take the user
@@ -248,10 +249,13 @@ async function initCommandLine() {
248249

249250
const environments = app ? await globEnvironmentsFromStacks(appStacks, environmentGlobs) : environmentsFromDescriptors(environmentGlobs);
250251

252+
// Bucket name can be passed using --toolkit-bucket-name or set in cdk.json
253+
const bucketName = configuration.settings.get(['toolkitBucketName']) || toolkitBucketName;
254+
251255
await Promise.all(environments.map(async (environment) => {
252256
success(' ⏳ Bootstrapping environment %s...', colors.blue(environment.name));
253257
try {
254-
const result = await bootstrapEnvironment(environment, aws, toolkitStackName, roleArn);
258+
const result = await bootstrapEnvironment(environment, aws, toolkitStackName, roleArn, bucketName);
255259
const message = result.noOp ? ' ✅ Environment %s bootstrapped (no changes).'
256260
: ' ✅ Environment %s bootstrapped.';
257261
success(message, colors.blue(environment.name));

packages/aws-cdk/lib/api/bootstrap-environment.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { SDK } from './util/sdk';
77
export const BUCKET_NAME_OUTPUT = 'BucketName';
88
export const BUCKET_DOMAIN_NAME_OUTPUT = 'BucketDomainName';
99

10-
export async function bootstrapEnvironment(environment: Environment, aws: SDK, toolkitStackName: string, roleArn: string | undefined): Promise<DeployStackResult> {
10+
export async function bootstrapEnvironment(environment: Environment, aws: SDK, toolkitStackName: string, roleArn: string | undefined, toolkitBucketName: string | undefined): Promise<DeployStackResult> {
1111
const synthesizedStack: SynthesizedStack = {
1212
environment,
1313
metadata: {},
@@ -35,5 +35,8 @@ export async function bootstrapEnvironment(environment: Environment, aws: SDK, t
3535
},
3636
name: toolkitStackName,
3737
};
38+
if (toolkitBucketName) {
39+
synthesizedStack.template.Resources.StagingBucket.Properties.BucketName = toolkitBucketName;
40+
}
3841
return await deployStack({ stack: synthesizedStack, sdk: aws, roleArn });
3942
}

0 commit comments

Comments
 (0)