From 824160da7729fc8c80f17e73af5bcc95dcf8231b Mon Sep 17 00:00:00 2001 From: adrians5j Date: Thu, 18 Jan 2024 11:13:26 +0100 Subject: [PATCH] refactor: move constants around --- .../cwp-template-aws/cli/aws/checkCredentials.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/cwp-template-aws/cli/aws/checkCredentials.js b/packages/cwp-template-aws/cli/aws/checkCredentials.js index 15cec76ef69..ac38f2d78f0 100644 --- a/packages/cwp-template-aws/cli/aws/checkCredentials.js +++ b/packages/cwp-template-aws/cli/aws/checkCredentials.js @@ -9,11 +9,6 @@ module.exports = { // Check if AWS credentials are configured const sts = new STS(); - const config = sts.config; - const region = await config.region(); - - // With AWS-SDK v3, we can no longer read the loaded profile. We try to read if from env var instead. - const profile = process.env.AWS_PROFILE || "default"; try { await sts.getCallerIdentity({}); @@ -31,6 +26,9 @@ module.exports = { process.exit(1); } + const config = sts.config; + const region = await config.region(); + if (!region) { console.log(); context.error("You must define an AWS Region to deploy to!"); @@ -49,6 +47,10 @@ module.exports = { const { accessKeyId } = await config.credentials(); + // With AWS-SDK v3, we can't no longer read the loaded profile. + // So, we try to read it from environment variables instead. + const profile = process.env.AWS_PROFILE || "default"; + if (profile) { context.info(`Using profile ${green(profile)} in ${green(region)} region.`); } else {