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

posta 9 mesi fa268 visualizzazioni
2 Risposte
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
con risposta 9 mesi fa
  • 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
ESPERTO
Uri
con risposta 9 mesi fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande