|
1 | 1 | import * as fs from 'fs'; |
2 | 2 | import * as aws from 'aws-sdk'; |
3 | 3 | import * as dynamodb from 'aws-sdk/clients/dynamodb'; |
4 | | -import { resourceLimits } from 'node:worker_threads'; |
| 4 | +import * as camelCase from 'camelcase'; |
5 | 5 | const DEV_FILE_PATH = '../../../src/deployments/cdk/'; |
6 | 6 | const DEV_OUTPUTS_FILE_PATH = `${DEV_FILE_PATH}outputs.json`; |
7 | 7 |
|
8 | 8 | const env = process.env; |
9 | 9 | const acceleratorPrefix = env.ACCELERATOR_PREFIX || 'ASEA-'; |
| 10 | +const installerStackName = process.env.INSTALLER_STACK_NAME; |
| 11 | +const cfn = new aws.CloudFormation(); |
10 | 12 | const documentClient = new aws.DynamoDB.DocumentClient(); |
11 | 13 |
|
12 | 14 | export const scanDDBTable = async (tableName: string) => { |
@@ -49,6 +51,48 @@ export const writeConfigs = (configList: any) => { |
49 | 51 | } |
50 | 52 | } |
51 | 53 | }; |
| 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 | + |
52 | 96 | scanDDBTable(`${acceleratorPrefix}Outputs`) |
53 | 97 | .then(outputs => loadOutputs(outputs)) |
54 | 98 | .then(parsedOutputs => fs.writeFileSync(DEV_OUTPUTS_FILE_PATH, JSON.stringify(parsedOutputs, null, 2))); |
|
0 commit comments