Why Lambda Invocation resources doesn't do delete operation in CRUD lifecycle?

64 views Asked by At

I'm using Terraform CDK and I need to run Lambda when Infrastracture creates/deletes. For this reason I use LambdaInvocation (aws_lambda_invocation) resource in Terraform CDK. When I run

cdktf deploy 
  • it works, my lambda is created and invoked (I checked CloudWatch Logs), good, but when I run
cdktf destroy 
  • all Infrastracture is destroyed and Lambda is not invoked (There is no log about running the lambda function, the LogGroup is not created by Terraform so that I could see the logs).

Here the code that I use:

const lambdaFunction = new LambdaFunction(this, "fn", {
      functionName: "lifecycle-handler",
      role: role.arn,
      environment: {
        variables: {
          QUARKUS_LAMBDA_HANDLER: "lifecycle",
          ...PROD_ENV,
        },
      },
      timeout: 15,
      memorySize,
      architectures: ["arm64"],
      filename: asset.path,
      sourceCodeHash: asset.hash,
      runtime: asset.runtime,
      handler: asset.handler,
    });

new LambdaInvocation(this, "lifecycle-invocation", {
      functionName: lambdaFunction.functionName,
      input: JSON.stringify({}),
      lifecycleScope: "CRUD",
    });

Running this code the Lambda is invoked, but it's not when I destroy infrastructure. I've also checked it with the Lambda that I had created manually and in such a case it was invoked on both create/destroy lifecycles. I also noticed that Lambda's delete logs appeared once during testing this issue, but the logs were not full as though Lambda didn't managed to finish its invocation. It seems to me that the Lambda can't be invoked because it's removed before invocation or during this invocation (I'm not sure). I would like to find the reason of this problem and some solution, thanks.

0

There are 0 answers