Lambda function works by itself but not in Step

0

I am using the following example: https://docs.aws.amazon.com/textract/latest/dg/examples-export-table-csv.html

These work wonderfully when I run them as separate Lambda functions. However, I'm having a hard time with making them Step Functions.

Step Graph

StartDocAnalysis produces the following output:

{
  "Ainput": {
    "Comment": "Insert your JSON here"
  },
  "Aoutput": "42baaa094603ed5f656a8d54a144bfcd29caf1255666e11031b7ac6855b436b8"
}

GetDocAnalysis takes that as input, as such:

def lambda_handler(event, context):
    jobId = event['Aoutput']
    response_blocks = GetResults(jobId, file_name)

When I feed the JSON as input in a test invocation of GetDocAnalysis in Lambda, everything works great. When I run this in Step, StartDocAnalysis runs fine and then GetDocAnalysis produces the following error:

{
  "error": "KeyError",
  "cause": {
    "errorMessage": "'Blocks'",
    "errorType": "KeyError",
    "stackTrace": [
      "  File \"/var/task/lambda_function.py\", line 163, in lambda_handler\n    response_blocks = GetResults(jobId, file_name)\n",
      "  File \"/var/task/lambda_function.py\", line 43, in GetResults\n    blocks = response['Blocks']\n"
    ]
  }
}

I haven't been able to get the Step functions to produce any logging or console printing to tell me what it's actually seeing as input. So I'm stuck.

Edit: See the Task Input for the second Lambda function below. Task Input

已提问 9 个月前267 查看次数
2 回答
0

Step Functions by itself does not pass any event details when invoking a Lambda function. You can pass input via the InputPath, ResultPath and OutputPath from step to step or declare Parameters in your state machine. This way you would be able to get visibility of what is happening.

AWS
已回答 9 个月前
  • So despite the Task Input being listed, it's not actually passing it?

0

To find out what is going wrong there are two places you can look:

  1. Add a print message to your Lambda function to output the event object. This way you can see exactly what you got.
  2. StepFunctions by default generates logs in the service itself (they are not sent to CloudWatch Logs). So you can open the console and see exactly what was passed in the different steps.
profile pictureAWS
专家
Uri
已回答 9 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则