in source/infrastructure/lib/web-client-custom-resource-construct.ts [36:105]
constructor(scope: Construct, id: string, props: WebClientCustomResourceProps) {
super(scope, id);
/** Create BotCustomResource Policy */
const botCustomResourcePolicy = new Policy(this, 'WebClientCustomResourcePolicy', {
policyName: 'WebClientCustomResource',
statements: [
/** WebClient Bucket permissions */
new PolicyStatement({
effect: Effect.ALLOW,
actions: ['s3:ListBucket', 's3:GetBucketLocation'],
resources: [`arn:${Aws.PARTITION}:s3:::${props.sampleWebClientBucketName}`],
}),
new PolicyStatement({
effect: Effect.ALLOW,
actions: ['s3:GetObject', 's3:PutObject', 's3:DeleteObject'],
resources: [`arn:${Aws.PARTITION}:s3:::${props.sampleWebClientBucketName}/*`],
}),
/** BotApi permissions */
new PolicyStatement({
effect: Effect.ALLOW,
actions: ['apigateway:POST'],
resources: [
`arn:${Aws.PARTITION}:apigateway:${Aws.REGION}::/restapis/${props.botApiId}/deployments`,
],
}),
],
});
/** Build CustomResource Lambda */
const customResourceLambda = buildLambdaFunction(this, {
lambdaFunctionProps: {
description: 'Function to setup webclient files',
runtime: Runtime.PYTHON_3_8,
handler: 'lambda_function.handler',
timeout: Duration.minutes(3),
code: Code.fromAsset('../services/webclient-setup'),
memorySize: 128,
},
});
/** Attache CustomResource Policy to Lambda's role */
customResourceLambda.role?.attachInlinePolicy(botCustomResourcePolicy); //NOSONAR it is a valid expression
/** Create Custom resource */
new CustomResource(this, 'CreateWebClientConfig', {
resourceType: 'Custom::CreateWebClientConfig',
serviceToken: customResourceLambda.functionArn,
properties: {
AwsRegion: Aws.REGION,
ApiUri: props.botApiUrl,
BotName: props.botName,
BotLanguage: props.botLanguage,
BotGender: props.botGender,
SampleWebClientBucket: props.sampleWebClientBucketName,
SampleWebclientPackage: props.sampleWebclientPackage,
CognitoIdentityPool: props.cognitoIdentityPool,
CognitoUserPoolId: props.cognitoUserPoolId,
CognitoUserPoolClientId: props.cognitoUserPoolClientId,
},
});
/** Suppression for cfn nag W92 */
const cfnFunction = customResourceLambda.node.defaultChild as CfnFunction;
CfnNagHelper.addSuppressions(cfnFunction, {
Id: 'W92',
Reason: 'This function does not need to have specified reserved concurrent executions'
});
}