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달 전268회 조회
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달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠