Skip to content

Commit

Permalink
refactor: move constants around
Browse files Browse the repository at this point in the history
  • Loading branch information
adrians5j committed Jan 18, 2024
1 parent df5049c commit 824160d
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/cwp-template-aws/cli/aws/checkCredentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({});
Expand All @@ -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!");
Expand All @@ -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 {
Expand Down

0 comments on commit 824160d

Please sign in to comment.