diff --git a/packages/aws-cdk/bin/cdk.ts b/packages/aws-cdk/bin/cdk.ts index c91f10123ab8e..e505d6c6ef9d5 100644 --- a/packages/aws-cdk/bin/cdk.ts +++ b/packages/aws-cdk/bin/cdk.ts @@ -30,6 +30,7 @@ const DEFAULT_TOOLKIT_STACK_NAME = 'CDKToolkit'; async function parseCommandLineArguments() { const initTemplateLanuages = await availableInitLanguages; return yargs + .env('CDK') .usage('Usage: cdk -a COMMAND') .option('app', { type: 'string', alias: 'a', desc: 'REQUIRED: Command-line for executing your CDK app (e.g. "node bin/my-app.js")' }) .option('context', { type: 'array', alias: 'c', desc: 'Add contextual string parameter.', nargs: 1, requiresArg: 'KEY=VALUE' }) diff --git a/packages/aws-cdk/lib/commands/doctor.ts b/packages/aws-cdk/lib/commands/doctor.ts index 4fd301c2ff16e..8b19bb3be0cbc 100644 --- a/packages/aws-cdk/lib/commands/doctor.ts +++ b/packages/aws-cdk/lib/commands/doctor.ts @@ -1,3 +1,4 @@ +import cxapi = require('@aws-cdk/cx-api'); import colors = require('colors/safe'); import process = require('process'); import yargs = require('yargs'); @@ -25,7 +26,8 @@ export async function realHandler(_options: CommandOptions): Promise { const verifications: Array<() => boolean | Promise> = [ displayVersionInformation, - displayAwsEnvironmentVariables + displayAwsEnvironmentVariables, + displayCdkEnvironmentVariables, ]; // ### Verifications ### @@ -47,3 +49,22 @@ function displayAwsEnvironmentVariables() { } return true; } + +function displayCdkEnvironmentVariables() { + const keys = Object.keys(process.env).filter(s => s.startsWith('CDK_')); + if (keys.length === 0) { + print('ℹ️ No CDK environment variables'); + return true; + } + print('ℹ️ CDK environment variables:'); + let healthy = true; + for (const key of keys.sort()) { + if (key === cxapi.CONTEXT_ENV || key === cxapi.OUTDIR_ENV) { + print(` - ${colors.red(key)} = ${colors.green(process.env[key]!)} (⚠️ reserved for use by the CDK toolkit)`); + healthy = false; + } else { + print(` - ${colors.blue(key)} = ${colors.green(process.env[key]!)}`); + } + } + return healthy; +}