1+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+ // SPDX-License-Identifier: Apache-2.0
13import * as cdk from "aws-cdk-lib" ;
24import * as ec2 from "aws-cdk-lib/aws-ec2" ;
35import * as events from "aws-cdk-lib/aws-events" ;
@@ -15,8 +17,6 @@ import { readAccountConfig } from "../../config/targets";
1517import { readResourceConfig } from "../../config/resources" ;
1618import * as fs from 'fs' ;
1719
18- const variableConfigJson = JSON . parse ( fs . readFileSync ( '../../config/variables.json' , 'utf-8' ) ) ;
19-
2020const toolName = process . env . TOOL_NAME ?? "defaultToolName" ;
2121
2222class PluginStack extends cdk . Stack {
@@ -25,7 +25,7 @@ class PluginStack extends cdk.Stack {
2525 private batchMemory : string ;
2626 private batchVcpus : string ;
2727
28- constructor ( scope : Construct , id : string , props ?: cdk . StackProps ) {
28+ constructor ( scope : Construct , id : string , variables : Record < string , string > , props ?: cdk . StackProps ) {
2929 super ( scope , id , props ) ;
3030
3131 const acctConfig = readAccountConfig ( "../../config/targets.yaml" ) ;
@@ -62,7 +62,7 @@ class PluginStack extends cdk.Stack {
6262 ) ;
6363 }
6464
65- private initBatchFargate ( ) : [ batch . CfnJobDefinition , batch . CfnJobQueue ] {
65+ private initBatchFargate ( variables : Record < string , string > ) : [ batch . CfnJobDefinition , batch . CfnJobQueue ] {
6666 const batchExecutionRole = new iam . Role (
6767 this ,
6868 `BatchExecutionRole-${ toolName } ` ,
@@ -118,11 +118,13 @@ class PluginStack extends cdk.Stack {
118118
119119 const containerImageUri = `${ this . adminAccountId } .dkr.ecr.us-east-1.amazonaws.com/${ toolName } :latest` ;
120120
121- // Convert JSON to environment variable format for Batch.
122- const environmentVariables = Object . entries ( variableConfigJson ) . map ( ( [ key , value ] ) => ( {
123- name : key ,
124- value : value as string ,
125- } ) ) ;
121+ // Convert JSON array to environment variable format for Batch.
122+ const environmentVariables = variables . map ( ( obj : Record < string , string > ) =>
123+ Object . entries ( obj ) . map ( ( [ key , value ] ) => ( {
124+ name : key ,
125+ value : value as string ,
126+ } ) )
127+ ) . flat ( ) ;
126128
127129 const jobDefinition = new batch . CfnJobDefinition ( this , "JobDefn" , {
128130 type : "container" ,
@@ -235,6 +237,7 @@ class PluginStack extends cdk.Stack {
235237 }
236238
237239 private initLogFunction ( adminBucketName : string ) : void {
240+ // S3 Bucket to store logs within this account.
238241 const bucket = new s3 . Bucket ( this , "LogBucket" , {
239242 versioned : false ,
240243 blockPublicAccess : s3 . BlockPublicAccess . BLOCK_ALL ,
0 commit comments