Skip to content

Commit 6072d31

Browse files
authored
Added context to developer script load-outputs (#928)
Co-authored-by: hickeydh <hickeydh@amazon.com>
1 parent a6156b6 commit 6072d31

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

reference-artifacts/Custom-Scripts/Developer-Script/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"lint:eslint": "pnpx eslint '{cdk,lib,src}/**/*.{js,ts}'"
99
},
1010
"dependencies": {
11-
"aws-sdk": "^2.1034.0"
11+
"aws-sdk": "^2.1034.0",
12+
"camelcase": "^6.3.0"
1213
},
1314
"devDependencies": {
1415
"@types/node": "14.14.31",

reference-artifacts/Custom-Scripts/Developer-Script/src/load-outputs.ts

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import * as fs from 'fs';
22
import * as aws from 'aws-sdk';
33
import * as dynamodb from 'aws-sdk/clients/dynamodb';
4-
import { resourceLimits } from 'node:worker_threads';
4+
import * as camelCase from 'camelcase';
55
const DEV_FILE_PATH = '../../../src/deployments/cdk/';
66
const DEV_OUTPUTS_FILE_PATH = `${DEV_FILE_PATH}outputs.json`;
77

88
const env = process.env;
99
const acceleratorPrefix = env.ACCELERATOR_PREFIX || 'ASEA-';
10+
const installerStackName = process.env.INSTALLER_STACK_NAME;
11+
const cfn = new aws.CloudFormation();
1012
const documentClient = new aws.DynamoDB.DocumentClient();
1113

1214
export const scanDDBTable = async (tableName: string) => {
@@ -49,6 +51,48 @@ export const writeConfigs = (configList: any) => {
4951
}
5052
}
5153
};
54+
55+
export const describeStack = async (cfnClient: AWS.CloudFormation, stackName: string | undefined) => {
56+
if (!stackName) {
57+
throw new Error('Please set the environment variable for INSTALLER_STACK_NAME');
58+
}
59+
60+
try {
61+
const describeStackParams = {
62+
StackName: stackName,
63+
};
64+
return cfnClient.describeStacks(describeStackParams).promise();
65+
} catch (err) {
66+
console.log(`Check to make sure the stack ${stackName} exists`);
67+
throw err;
68+
}
69+
};
70+
71+
const context: any = {};
72+
73+
describeStack(cfn, installerStackName)
74+
.then(stackInfo => {
75+
const params = stackInfo.Stacks![0].Parameters;
76+
if (params) {
77+
for (const param of params) {
78+
const key = camelCase(param.ParameterKey!);
79+
const value = param.ParameterValue!;
80+
context[key] = value;
81+
}
82+
}
83+
context['acceleratorExecutionRoleName'] = `${context.acceleratorPrefix}PipelineRole`;
84+
context['defaultRegion'] = process.env.AWS_REGION || 'us-west-2';
85+
context['acceleratorPipelineRoleName'] = `${context.acceleratorPrefix}PipelineRole`;
86+
context['acceleratorStateMachineName'] = `${context.acceleratorPrefix}MainStateMachine_sm`;
87+
context['installerVersion'] = '1.5.0';
88+
context['vpcCidrPoolAssignedTable'] = `${context.acceleratorPrefix}cidr-vpc-assign`;
89+
context['subnetCidrPoolAssignedTable'] = `${context.acceleratorPrefix}cidr-subnet-assign`;
90+
context['cidrPoolTable'] = `${context.acceleratorPrefix}cidr-pool`;
91+
console.log(JSON.stringify(context, null, 2));
92+
return context;
93+
})
94+
.then(context => fs.writeFileSync(`${DEV_FILE_PATH}context.json`, JSON.stringify(context, null, 2)));
95+
5296
scanDDBTable(`${acceleratorPrefix}Outputs`)
5397
.then(outputs => loadOutputs(outputs))
5498
.then(parsedOutputs => fs.writeFileSync(DEV_OUTPUTS_FILE_PATH, JSON.stringify(parsedOutputs, null, 2)));

0 commit comments

Comments
 (0)