Search code examples
typescriptamazon-web-servicesaws-lambdaaws-cdkaws-step-functions

Why does Step Functions task fails after submission?


I have just started out with steps functions so feel free to ask for details if my question is ambiguous!

What I am trying to achieve:- I am trying to upload a file which triggers lambda function as a task invoked by the step function.

What is the problem :- The task & lambda invoked by step functions work flawlessly for other files, but the task after submission fails for this particular file lets call its xyz.sdb

What i have tried :- I have tried to fetch the logs of task submission and taks failed in the console

Logs for task submitted

{
  "resourceType": "lambda",
  "resource": "invoke.waitForTaskToken",
  "output": {
    "ExecutedVersion": "$LATEST",
    "Payload": null,
    "SdkHttpMetadata": {
      "AllHttpHeaders": {
        "X-Amz-Executed-Version": [
          "$LATEST"
        ],
        "x-amzn-Remapped-Content-Length": [
          "0"
        ],
        "Connection": [
          "keep-alive"
        ],
        "x-amzn-RequestId": [
          "xxxxxxxxx"
        ],
        "Content-Length": [
          "4"
        ],
        "Date": [
          "Thu, 14 Jul 2022 02:41:08 GMT"
        ],
        "X-Amzn-Trace-Id": [
          "root=1-xxxxxx-xxxxxa3e5ed0cb1d6ff;sampled=0"
        ],
        "Content-Type": [
          "application/json"
        ]
      },
      "HttpHeaders": {
        "Connection": "keep-alive",
        "Content-Length": "4",
        "Content-Type": "application/json",
        "Date": "Thu, 14 Jul 2022 02:41:08 GMT",
        "X-Amz-Executed-Version": "$LATEST",
        "x-amzn-Remapped-Content-Length": "0",
        "x-amzn-RequestId": "xxxxxx-d73a-499f-8e3c-f9ca904f94a0",
        "X-Amzn-Trace-Id": "root=1-xxxx-4f64750d7ea3e5ed0cb1d6ff;sampled=0"
      },
      "HttpStatusCode": 200
    },
    "SdkResponseMetadata": {
      "RequestId": "xxxxxxxxx-d73a-499f-8e3c-xxxxxx"
    },
    "StatusCode": 200
  },
  "outputDetails": {
    "truncated": false
  }
} 

Logs for task failed

{
  "resourceType": "lambda",
  "resource": "invoke.waitForTaskToken",
  "error": null,
  "cause": null
}

How am i deploying my step function :-

const sdbWholeFileExtractionFunction = new LambdaFunction(
      this,
      'SdbWholeFileExtractionFunction',
      {
        functionProps: {
          code: lambda.Code.fromAsset('dist/workflow/task'),
          handler: 'sdb-whole-file-extraction.handle',
          environment: {
            CLUSTER: cluster.clusterArn,
            SUBNET_IDS: JSON.stringify(subnetIds),
            TASK_DEFINITION: taskDefinition.family,
            CONTAINER_NAME: container.containerName,
          },
        },
        targetTopic: props.targetTopic,
      }
    )
    runTaskPolicy.attachToRole(
      sdbWholeFileExtractionFunction.lambdaFunction.role!
    )
    const sdbWholeFileExtractionInvocation = new tasks.LambdaInvoke(
      this,
      'SdbWholeFileExtractionInvocation',
      {
        lambdaFunction: sdbWholeFileExtractionFunction.lambdaFunction,
        integrationPattern: sfn.IntegrationPattern.WAIT_FOR_TASK_TOKEN,
        payload: sfn.TaskInput.fromObject({
          bookId: sfn.JsonPath.stringAt('$.bookData.bookId'),
          prefix: sfn.JsonPath.stringAt('$.bookData.prefix'),
          isDiffPackageUploaded: sfn.JsonPath.stringAt(
            '$.bookData.isDiffPackageUploaded'
          ),
          token: sfn.JsonPath.taskToken,
        }),
      }
    )

Can anyone guide where to look for status code or error from step function or lambda? In my opinion, this looks like a problem for lambda with this particular file.


Solution

  • I figured out the solution, it's not the step functions, in my case, the problem was with file decompression, which led the step function to fail.

    In such cases, if other files are working good with step functions, it is better to check for file contents.