diff --git a/packages/aws-cdk/README.md b/packages/aws-cdk/README.md index 7fd8bff8b8057..2450bdc7aa2ed 100644 --- a/packages/aws-cdk/README.md +++ b/packages/aws-cdk/README.md @@ -164,11 +164,12 @@ configuration's order of precedence is: Some of the interesting keys that can be used in the JSON configuration files: ```js { - "app": "node bin/main.js", // Command to start the CDK app (--app='node bin/main.js') - "context": { // Context entries (--context=key=value) + "app": "node bin/main.js", // Command to start the CDK app (--app='node bin/main.js') + "context": { // Context entries (--context=key=value) "key": "value", }, - "toolkitStackName": "foo", // Customize 'bootstrap' stack name (--toolkit-stack-name=foo) - "versionReporting": false, // Opt-out of version reporting (--no-version-reporting) + "toolkitStackName": "foo", // Customize 'bootstrap' stack name (--toolkit-stack-name=foo) + "toolkitBucketName": "fooBucket", // Customize 'bootstrap' bucket name(--toolkit-bucket-name=fooBucket) + "versionReporting": false, // Opt-out of version reporting (--no-version-reporting) } ``` diff --git a/packages/aws-cdk/bin/cdk.ts b/packages/aws-cdk/bin/cdk.ts index 91f0ebffe3919..421ff6dc2831b 100644 --- a/packages/aws-cdk/bin/cdk.ts +++ b/packages/aws-cdk/bin/cdk.ts @@ -56,7 +56,8 @@ async function parseCommandLineArguments() { .option('interactive', { type: 'boolean', alias: 'i', desc: 'interactively watch and show template updates' }) .option('output', { type: 'string', alias: 'o', desc: 'write CloudFormation template for requested stacks to the given directory', requiresArg: true }) .option('numbered', { type: 'boolean', alias: 'n', desc: 'prefix filenames with numbers to indicate deployment ordering' })) - .command('bootstrap [ENVIRONMENTS..]', 'Deploys the CDK toolkit stack into an AWS environment') + .command('bootstrap [ENVIRONMENTS..]', 'Deploys the CDK toolkit stack into an AWS environment', yargs => yargs + .option('toolkit-bucket-name', { type: 'string', alias: 'b', desc: 'The name of the CDK toolkit bucket', default: undefined })) .command('deploy [STACKS..]', 'Deploys the stack(s) named STACKS into your AWS account', yargs => yargs .option('build-exclude', { type: 'array', alias: 'E', nargs: 1, desc: 'do not rebuild asset with the given ID. Can be specified multiple times.', default: [] }) .option('exclusively', { type: 'boolean', alias: 'e', desc: 'only deploy requested stacks, don\'t include dependencies' }) @@ -189,7 +190,7 @@ async function initCommandLine() { }); case 'bootstrap': - return await cliBootstrap(args.ENVIRONMENTS, toolkitStackName, args.roleArn); + return await cliBootstrap(args.ENVIRONMENTS, toolkitStackName, args.roleArn, args.toolkitBucketName); case 'deploy': return await cli.deploy({ @@ -238,7 +239,7 @@ async function initCommandLine() { * all stacks are implicitly selected. * @param toolkitStackName the name to be used for the CDK Toolkit stack. */ - async function cliBootstrap(environmentGlobs: string[], toolkitStackName: string, roleArn: string | undefined): Promise { + async function cliBootstrap(environmentGlobs: string[], toolkitStackName: string, roleArn: string | undefined, toolkitBucketName: string | undefined): Promise { // Two modes of operation. // // 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() { const environments = app ? await globEnvironmentsFromStacks(appStacks, environmentGlobs) : environmentsFromDescriptors(environmentGlobs); + // Bucket name can be passed using --toolkit-bucket-name or set in cdk.json + const bucketName = configuration.settings.get(['toolkitBucketName']) || toolkitBucketName; + await Promise.all(environments.map(async (environment) => { success(' ⏳ Bootstrapping environment %s...', colors.blue(environment.name)); try { - const result = await bootstrapEnvironment(environment, aws, toolkitStackName, roleArn); + const result = await bootstrapEnvironment(environment, aws, toolkitStackName, roleArn, bucketName); const message = result.noOp ? ' ✅ Environment %s bootstrapped (no changes).' : ' ✅ Environment %s bootstrapped.'; success(message, colors.blue(environment.name)); diff --git a/packages/aws-cdk/lib/api/bootstrap-environment.ts b/packages/aws-cdk/lib/api/bootstrap-environment.ts index 122899919e97a..d2c751b36b6dc 100644 --- a/packages/aws-cdk/lib/api/bootstrap-environment.ts +++ b/packages/aws-cdk/lib/api/bootstrap-environment.ts @@ -7,7 +7,7 @@ import { SDK } from './util/sdk'; export const BUCKET_NAME_OUTPUT = 'BucketName'; export const BUCKET_DOMAIN_NAME_OUTPUT = 'BucketDomainName'; -export async function bootstrapEnvironment(environment: Environment, aws: SDK, toolkitStackName: string, roleArn: string | undefined): Promise { +export async function bootstrapEnvironment(environment: Environment, aws: SDK, toolkitStackName: string, roleArn: string | undefined, toolkitBucketName: string | undefined): Promise { const synthesizedStack: SynthesizedStack = { environment, metadata: {}, @@ -35,5 +35,8 @@ export async function bootstrapEnvironment(environment: Environment, aws: SDK, t }, name: toolkitStackName, }; + if (toolkitBucketName) { + synthesizedStack.template.Resources.StagingBucket.Properties.BucketName = toolkitBucketName; + } return await deployStack({ stack: synthesizedStack, sdk: aws, roleArn }); }