in source/cdk-infrastructure/lib/solution-helper/solution-helper-construct.ts [26:102]
constructor(scope: Construct, id: string, props: ISolutionHelperProps) {
super(scope, id);
this.sourceCodeBucket = Bucket.fromBucketName(this, 'sourceCodeBucket', props.sourceCodeBucketName);
this.sourceCodeKeyPrefix = props.sourceCodeKeyPrefix;
const generateSolutionConstantsLambda = new LambdaFunction(this, 'GenerateSolutionConstantsLambda', {
runtime: Runtime.NODEJS_14_X,
handler: 'solution-helper/index.handler',
timeout: Duration.seconds(3),
description: 'Generates an anonymous UUID and a lower case stack name for sending metrics and resource creation',
code: Code.fromBucket(this.sourceCodeBucket, [props.sourceCodeKeyPrefix, 'solution-helper.zip'].join('/')),
environment: { STACK_NAME: Aws.STACK_NAME }
});
// Suppress CFN Nag warnings
(generateSolutionConstantsLambda.node.findChild('Resource') as CfnFunction).addMetadata('cfn_nag', {
rules_to_suppress: [
{
id: 'W58',
reason: 'CloudWatch permissions are granted by the LambdaBasicExecutionRole'
},
{
id: 'W89',
reason: 'VPC for Lambda is not needed. This serverless architecture does not deploy a VPC.'
},
{
id: 'W92',
reason: 'ReservedConcurrentExecutions is not needed for this Lambda function.'
}
]
});
const generateSolutionConstantsCustomResource = new CustomResource(this, 'GenerateSolutionConstantsCustomResource', {
serviceToken: generateSolutionConstantsLambda.functionArn,
properties: { Action: 'GENERATE_SOLUTION_CONSTANTS' }
});
this.anonymousDataUUID = generateSolutionConstantsCustomResource.getAttString('AnonymousDataUUID');
this.lowerCaseStackName = generateSolutionConstantsCustomResource.getAttString('LowerCaseStackName');
this.customResourceLambda = new LambdaFunction(this, 'CustomResourceLambda', {
runtime: Runtime.NODEJS_14_X,
handler: 'solution-helper/index.handler',
timeout: Duration.minutes(2),
description: 'Performs various Solution lifecycle actions when invoked as a CloudFormation Custom Resource',
code: Code.fromBucket(this.sourceCodeBucket, [props.sourceCodeKeyPrefix, 'solution-helper.zip'].join('/')),
environment: {
SEND_ANONYMOUS_DATA: props.sendAnonymousData,
ANONYMOUS_DATA_UUID: this.anonymousDataUUID,
SOLUTION_ID: props.solutionId,
SOLUTION_VERSION: props.solutionVersion
}
});
// Suppress CFN Nag warnings
(this.customResourceLambda.node.findChild('Resource') as CfnFunction).addMetadata('cfn_nag', {
rules_to_suppress: [
{
id: 'W58',
reason: 'CloudWatch permissions are granted by the LambdaBasicExecutionRole'
},
{
id: 'W89',
reason: 'VPC for Lambda is not needed. This serverless architecture does not deploy a VPC.'
},
{
id: 'W92',
reason: 'ReservedConcurrentExecutions is not needed for this Lambda function.'
}
]
});
const solutionLifecycleMetricCustomResource = new CfnCustomResource(this, 'SolutionLifecycleMetricCustomResource', { serviceToken: this.customResourceLambda.functionArn });
solutionLifecycleMetricCustomResource.addPropertyOverride('Action', 'SOLUTION_LIFECYCLE');
solutionLifecycleMetricCustomResource.addPropertyOverride('SolutionParameters', { DeployM2C: props.deployM2CParameter });
solutionLifecycleMetricCustomResource.cfnOptions.condition = props.anonymousUsageCondition;
}