From 332ce4d9ae995bd1336fef13e2c7f9fc0c12f34d Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Fri, 5 Nov 2021 12:58:12 +0100 Subject: [PATCH] fix(cli): `wmic not found` on modern Windows systems (#17070) Apparently Microsoft stopped shipping `wmic.exe` in certain situations (modern systems?). We rely on this to detect whether we are on an EC2 instance, so that we do or do not configure the IMDS credential provider (we try to avoid the IMDS credential provider if unnecessary, because in certain network setups it may hang for a long time failing to connect to `169.254.169.254`). If calling `wmic` fails, just assume we're not on an EC2 instance and proceed. Fixes #16419. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../lib/api/aws-auth/awscli-compatible.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/aws-cdk/lib/api/aws-auth/awscli-compatible.ts b/packages/aws-cdk/lib/api/aws-auth/awscli-compatible.ts index b409274efa59c..eb141768b9644 100644 --- a/packages/aws-cdk/lib/api/aws-auth/awscli-compatible.ts +++ b/packages/aws-cdk/lib/api/aws-auth/awscli-compatible.ts @@ -177,12 +177,18 @@ async function isEc2Instance() { let instance = false; if (process.platform === 'win32') { // https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/identify_ec2_instances.html - const result = await util.promisify(child_process.exec)('wmic path win32_computersystemproduct get uuid', { encoding: 'utf-8' }); - // output looks like - // UUID - // EC2AE145-D1DC-13B2-94ED-01234ABCDEF - const lines = result.stdout.toString().split('\n'); - instance = lines.some(x => matchesRegex(/^ec2/i, x)); + try { + const result = await util.promisify(child_process.exec)('wmic path win32_computersystemproduct get uuid', { encoding: 'utf-8' }); + // output looks like + // UUID + // EC2AE145-D1DC-13B2-94ED-01234ABCDEF + const lines = result.stdout.toString().split('\n'); + instance = lines.some(x => matchesRegex(/^ec2/i, x)); + } catch (e) { + // Modern machines may not have wmic.exe installed. No reason to fail, just assume it's not an EC2 instance. + debug(`Checking using WMIC failed, assuming NOT an EC2 instance: ${e.message} (pass --ec2creds to force)`); + instance = false; + } } else { // https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/identify_ec2_instances.html const files: Array<[string, RegExp]> = [