Skip to content

Commit

Permalink
fix(cli): remove loading of local aws config / credentials to avoid r…
Browse files Browse the repository at this point in the history
…untime issues

if AWS_SDK_LOAD_CONFIG will be loaded the aws config and credentials file will be checked. An error
occurs when these files have not been set.
  • Loading branch information
Fuss Florian (uid10804) committed Jan 2, 2021
1 parent 2ad108a commit 858b4d2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
19 changes: 3 additions & 16 deletions packages/cli/src/actions/aws-actions.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
process.env.AWS_SDK_LOAD_CONFIG = 'true';
import AWS = require('aws-sdk');

const ec2: AWS.EC2 = new AWS.EC2();
const ec2: AWS.EC2 = new AWS.EC2({ region: 'us-east-1' });
const cloudformation: AWS.CloudFormation = new AWS.CloudFormation();
const sts: AWS.STS = new AWS.STS();
/* if (!AWS.config.region) {
AWS.config.update({ region: 'us-east-1' });
}
*/

export class AWSActions {
constructor() {}
static getCurrentRegion(): string {
if (!AWS.config.region) {
AWS.config.update({ region: 'us-east-1' });
}
return AWS.config.region!;
}

static async checkValidAWSIdentity(): Promise<
AWS.STS.GetCallerIdentityResponse
Expand All @@ -32,15 +21,13 @@ export class AWSActions {

static async getAllRegionsByName(): Promise<Array<Object>> {
try {
let regions: Object[];
let regions: string[] = [];
const result = await ec2.describeRegions({ AllRegions: true }).promise();

regions = result
.Regions!.sort((a, b) => a.RegionName!.localeCompare(b.RegionName!))
.map((x) => {
return new Object({
name: x.RegionName,
});
return x.RegionName!;
});
return regions;
} catch (error) {
Expand Down
15 changes: 13 additions & 2 deletions packages/cli/src/commands/create-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export class CreateStackCommand extends Command {
let region: string | undefined;
if (flags.region) {
region = flags.region;
await this.verifyRegion(region);
} else {
region = await this.getRegion();
}
Expand Down Expand Up @@ -312,6 +313,17 @@ export class CreateStackCommand extends Command {
}
}

private async verifyRegion(region: string | undefined) {
let regions = await AWSActions.getAllRegionsByName();
if (!regions.find((x) => x === region)) {
this.error(
'Please check the value for the region parameter - the region ' +
region +
' cannot be found in aws and is not valid'
);
}
}

private async checkIdentity() {
cli.action.start(
`${chalk.blueBright('Check AWS Identity')}`,
Expand Down Expand Up @@ -364,8 +376,7 @@ export class CreateStackCommand extends Command {

private async getRegion() {
let regions = await AWSActions.getAllRegionsByName();
regions.unshift({ name: AWSActions.getCurrentRegion() });
let region = '';
let region = null;

let responses: any = await inquirer.prompt([
{
Expand Down

0 comments on commit 858b4d2

Please sign in to comment.