// Using Custom resources
const checkExecutionLambda = new lambda.Function(this, 'CheckExecutionFunction', {
runtime: lambda.Runtime.NODEJS_12_X,
handler: 'step-func.handler',
code: lambda.Code.fromAsset(path.join(__dirname, '../lambda')),
memorySize: 256,
timeout: cdk.Duration.minutes(15),
// tracing: lambda.Tracing.ACTIVE,
environment: {
STATE_MACHINE_ARN: ecrStateMachine.stateMachineArn
}
});
//Run checkExecutionLambda on Create
const lambdaTrigger = new cr.AwsCustomResource(this, 'StatefunctionTrigger', {
policy: cr.AwsCustomResourcePolicy.fromStatements([new iam.PolicyStatement({
actions: ['lambda:InvokeFunction'],
effect: iam.Effect.ALLOW,
resources: [checkExecutionLambda.functionArn]
})]),
timeout: cdk.Duration.minutes(15),
onCreate: {
service: 'Lambda',
action: 'invoke',
parameters: {
FunctionName: checkExecutionLambda.functionName,
InvocationType: 'Event'
},
physicalResourceId: cr.PhysicalResourceId.of('JobSenderTriggerPhysicalId')
},
onUpdate: {
service: 'Lambda',
action: 'invoke',
parameters: {
FunctionName: checkExecutionLambda.functionName,
InvocationType: 'Event'
},
physicalResourceId: cr.PhysicalResourceId.of('JobSenderTriggerPhysicalId')
}
})