constructor()

in cdk-stacks/lib/recording/cdk-chime-event-bridge-stack.ts [23:62]


    constructor(scope: cdk.Construct, id: string, props: CdkChimeEventBridgeStackProps) {
        super(scope, id, props);

        //Subscribe to Amazon Chime SDK meeting ends
        const chimeMeetingEndsRule = new events.Rule(this, 'ChimeMeetingEndsRule', {
            description: `Rule triggered by Amazon Chime SDK, when an active meeting ends.`,
            eventPattern: {
                source: ['aws.chime'],
                detail: {
                    'eventType': ['chime:MeetingEnded']
                }
            }
        });

        const stopRecordingEventTargetLambda = new nodeLambda.NodejsFunction(this, 'StopRecordingEventTargetLambda', {
            functionName: `${configParams['CdkAppName']}-StopRecordingEventTargetLambda`,
            runtime: lambda.Runtime.NODEJS_12_X,
            entry: 'lambdas/handlers/RecordingAPI/stopRecordingEventTarget.js',
            timeout: cdk.Duration.seconds(20),
            environment: {
                DDB_TABLE: props.appTable.tableName,
                DDB_REGION: props.cdkBackendStackRegion,
                ECS_CLUSTER_ARN: props.recordingECSClusterARN,
                ECS_CLUSTER_REGION: props.cdkBackendStackRegion
            }
        });
        props.appTable.grantReadWriteData(stopRecordingEventTargetLambda);

        stopRecordingEventTargetLambda.role?.attachInlinePolicy(new iam.Policy(this, 'ECSStopTaskAccess', {
            statements: [
                new iam.PolicyStatement({
                    effect: iam.Effect.ALLOW,
                    actions: ['ecs:StopTask'],
                    resources: [`arn:aws:ecs:${props.cdkBackendStackRegion}:${this.account}:task/${props.recordingECSClusterName}/*`]
                })
            ]
        }));

        chimeMeetingEndsRule.addTarget(new events_targets.LambdaFunction(stopRecordingEventTargetLambda));
    }