in source/infrastructure/lib/custom-resource.ts [76:136]
constructor(scope: Construct, id: string, props: CustomResourcesConstructProps) {
super(scope, id);
this.sourceCodeBucket = props.solutionConfig.sourceCodeBucket;
this.sourceCodePrefix = props.solutionConfig.sourceCodePrefix;
this.helperLambdaRole = new Role(this, 'HelperLambdaRole', {
assumedBy: new ServicePrincipal('lambda.amazonaws.com'),
path: '/',
inlinePolicies: {
'customResourcePolicy': new PolicyDocument({
statements: [
new PolicyStatement({
effect: Effect.ALLOW,
actions: ['iot:DescribeEndpoint'],
resources: ['*']
})
]
})
}
});
this.helperLambdaRole.attachInlinePolicy(props.cloudWatchLogsPolicy);
addCfnSuppressRules(this.helperLambdaRole, [
{ id: 'W11', reason: 'iot:DescribeEndpoint cannot specify the resource.' }
]);
this.helperLambda = new LambdaFunction(this, 'HelperLambda', {
description: 'IoT Device Simulator custom resource function',
handler: 'index.handler',
runtime: Runtime.NODEJS_14_X,
code: Code.fromBucket(this.sourceCodeBucket, `${this.sourceCodePrefix}/custom-resource.zip`),
timeout: Duration.seconds(240),
role: this.helperLambdaRole,
environment: {
SOLUTION_ID: props.solutionConfig.solutionId,
SOLUTION_VERSION: props.solutionConfig.solutionVersion
}
});
(this.helperLambda.node.defaultChild as CfnFunction).addDependsOn(props.cloudWatchLogsPolicy.node.defaultChild as CfnPolicy);
const customIds = new CustomResource(this, 'UUID', {
serviceToken: this.helperLambda.functionArn,
properties: {
Resource: 'CreateUUID',
StackName: Aws.STACK_NAME
}
});
this.uuid = customIds.getAtt('UUID').toString();
this.uniqueSuffix = customIds.getAtt('UNIQUE_SUFFIX').toString();
this.reducedStackName = customIds.getAtt('REDUCED_STACK_NAME').toString();
const customIotEndpoint = new CustomResource(this, 'EndpointAddress', {
serviceToken: this.helperLambda.functionArn,
properties: {
Resource: 'DescribeIoTEndpoint'
}
});
this.iotEndpoint = customIotEndpoint.getAtt('IOT_ENDPOINT').toString();
}