Step Function Choice Input/output mapping

0

Hi I have a step function that executes the lambda function first and then lambda simply returns the below output

"{\"job_status\": \"COMPLETE\"}"

Based on Job Status value next step to take decision to Complete OR Running

Here is step function:

{
  "Comment": "Create Macie Job for the file.",
  "StartAt": "CheckMacieJobStatus",
  "States": {
    "CheckMacieJobStatus": {
      "Type": "Task",
      "Resource": "arn:aws:states:::lambda:invoke",
      "OutputPath": "$.Payload",
      "InputPath": "$",
      "Parameters": {
        "Payload.$": "$",
        "FunctionName": "arn:aws:lambda:us-west-2:<account_id>:function:lambdafunction_name:$LATEST"
      },
      "Retry": [
        {
          "ErrorEquals": [
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "IntervalSeconds": 2,
          "MaxAttempts": 6,
          "BackoffRate": 2
        }
      ],
      "Next": "Choice"
    },
    "Choice": {
      "Type": "Choice",
      "Choices": [
        {
          "Variable": "$.job_status",
          "StringEquals": "RUNNING",
          "Next": "Wait120Seconds"
        },
        {
          "Variable": "$.job_status",
          "StringEquals": "COMPLETE",
          "Next": "Success"
        }
      ],
      "InputPath": "$.job_status"
    },
    "Wait120Seconds": {
      "Type": "Wait",
      "Seconds": 120,
      "Next": "CheckMacieJobStatus"
    },
    "Success": {
      "Type": "Succeed"
    }
  }
}

However after the first step, I am getting errors at the choice step. What am I missing here?

An error occurred while executing the state 'Choice' (entered at the event id #7). Invalid path '$.job_status' : Property ['job_status'] not found in path $
2개 답변
2

The error "Invalid path '$.job_status' : Property ['job_status'] not found in path $" suggests a mismatch between your Lambda function's output and what the Step Function expects. To fix this, ensure the Lambda output correctly aligns with the Step Function's expected input, particularly for the Choice state.

Given the structure of your Step Function, here are a few things to consider correcting the issue:

  • Confirm the Lambda returns {"job_status": "COMPLETE"} directly at the root of its JSON output.
  • If your Lambda output directly contains job_status at the root, ensure the OutputPath in the CheckMacieJobStatus state is "OutputPath": "$".
  • The InputPath in your Choice state might be unnecessary. Removing or adjusting it could resolve the error.

Corrected Step Function snippet:

"CheckMacieJobStatus": {
  "Type": "Task",
  "Resource": "arn:aws:states:::lambda:invoke",
  "OutputPath": "$",
  ...
},
"Choice": {
  "Type": "Choice",
  "Choices": [
    {
      "Variable": "$.job_status",
      "StringEquals": "RUNNING",
      "Next": "Wait120Seconds"
    },
    {
      "Variable": "$.job_status",
      "StringEquals": "COMPLETE",
      "Next": "Success"
    }
  ]
}

This assumes your Lambda function returns the expected structure. Align the Lambda's output or adjust the Step Function configuration accordingly.

profile picture
전문가
답변함 한 달 전
profile picture
전문가
검토됨 한 달 전
0
수락된 답변

by adding inputpath to $ fixed the issue>

{
  "Comment": "Create Macie Job for the file.",
  "StartAt": "CheckMacieJobStatus",
  "States": {
    "CheckMacieJobStatus": {
      "Type": "Task",
      "Resource": "arn:aws:states:::lambda:invoke",
      "OutputPath": "$.Payload",
      "InputPath": "$",
      "Parameters": {
        "Payload.$": "$",
        "FunctionName": "arn:aws:lambda:${aws_region}:${aws_account_id}:function: lambdafunction_name ${environment}:$LATEST"
      },
      "Retry": [
        {
          "ErrorEquals": [
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "IntervalSeconds": 2,
          "MaxAttempts": 6,
          "BackoffRate": 2
        }
      ],
      "Next": "Choice"
    },
    "Choice": {
      "Type": "Choice",
      "Choices": [
        {
          "Variable": "$.jobStatus",
          "StringEquals": "RUNNING",
          "Next": "Wait300Seconds"
        },
        {
          "Variable": "$.jobStatus",
          "StringEquals": "COMPLETE",
          "Next": "Success"
        }
      ],
      "InputPath": "$"
    },
    "Wait300Seconds": {
      "Type": "Wait",
      "Seconds": 300,
      "Next": "CheckMacieJobStatus"
    },
    "Success": {
      "Type": "Succeed"
    }
  }
}
답변함 한 달 전

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

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

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

관련 콘텐츠