in cdk-stacks/lib/frontend/frontend-config-stack.ts [18:58]
constructor(scope: cdk.Construct, id: string, props: FrontendConfigStackProps) {
super(scope, id, props);
const buildConfigParameters = () => {
const result: any = {};
props.backendStackOutputs.forEach(param => {
result[param.key] = param.value;
});
return JSON.stringify(result);
}
//frontend config custom resource
const frontendConfigLambda = new lambda.Function(this, `FrontendConfigLambda`, {
functionName: `${props.cdkAppName}-FrontendConfigLambda`,
runtime: lambda.Runtime.PYTHON_3_8,
code: lambda.Code.fromAsset('lambdas/custom-resources/frontend-config'),
handler: 'index.handler',
timeout: cdk.Duration.seconds(120),
initialPolicy: [new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
actions: ["s3:PutObject", "s3:DeleteObject"],
resources: [
`${props.webAppBucket.bucketArn}/${configParams['WebAppStagingPrefix']}frontend-config.zip`,
`${props.webAppBucket.bucketArn}/${configParams['WebAppRootPrefix']}frontend-config.js`
]
})]
});
const frontendConfigCustomResource = new cdk.CustomResource(this, `${props.cdkAppName}-FrontendConfigCustomResource`, {
resourceType: 'Custom::FrontendConfig',
serviceToken: frontendConfigLambda.functionArn,
properties: {
BucketName: props.webAppBucket.bucketName,
WebAppStagingObjectPrefix: configParams['WebAppStagingPrefix'],
WebAppRootObjectPrefix: configParams['WebAppRootPrefix'],
ObjectKey: `frontend-config.js`,
ContentType: 'text/javascript',
Content: `window.vceConfig = ${buildConfigParameters()}`
}
});
}