I created the following Step Functions. In the first Lambda Function, after getting the product_name and product_price, I generate a product ID. In the CheckStatusFrom_AddToCart step I check if everything is okay on the Lambda side and if there is, I move on to the next step. In this step (Success_AddToCart) I would like to send the product ID generated earlier along with the product_price and paid_price variables. How can I store that variable? Choice type does not support ResultPath.
{
"StartAt": "LambdaFunction_AddToCart",
"States": {
"LambdaFunction_AddToCart": {
"Type": "Task",
"Resource": "arn:aws:lambda:xxx",
"Parameters": {
"product_name": "Television",
"product_price": 1500
},
"Next": "CheckStatusFrom_AddToCart"
},
"CheckStatusFrom_AddToCart": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.statusCode",
"NumericEquals": 200,
"Next": "Success_AddToCart"
},
{
"Variable": "$.statusCode",
"NumericEquals": 400,
"Next": "Fail_AddToCart"
}
]
},
"Success_AddToCart": {
"Type": "Task",
"Resource": "arn:aws:yyy",
"Parameters": {
"product_price": 1500,
"paid_price": 1500
},
"Next": "CheckStatusFrom_Payment"
},
"Fail_AddToCart": {
"Type": "Fail"
},
"CheckStatusFrom_Payment": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.statusCode",
"NumericEquals": 200,
"Next": "Success_Payment"
},
{
"Variable": "$.statusCode",
"NumericEquals": 400,
"Next": "Fail_Payment"
}
]
},
"Success_Payment": {
"Type": "Pass",
"End": true
},
"Fail_Payment": {
"Type": "Fail"
}
}
}
UPDATE
I implemented ResultPath and I can forward an incoming value to the next step, so I can call LambdaFunction_MakePayment with the productID. But after that, in LambdaFunction_ThankYou, it's not working anymore:
An error occurred while executing the state 'LambdaFunction_ThankYou' (entered at the event id #18). The JSONPath '$.productID' specified for the field 'product_id.$' could not be found in the input '{"statusCode": 200, "body": "Paid price 1500 equals Product price 1500"}'
{
"StartAt": "LambdaFunction_AddToCart",
"States": {
"LambdaFunction_AddToCart": {
"Type": "Task",
"Resource": "arn:aws:xxx",
"Parameters": {
"product_name": "Television",
"product_price": 1500
},
"Next": "GetProductID_From_AddToCart"
},
"GetProductID_From_AddToCart": {
"Type": "Pass",
"ResultPath": "$.purchase",
"Result": { "product_id": "$.productID"},
"Next": "CheckStatusFrom_AddToCart"
},
"CheckStatusFrom_AddToCart": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.statusCode",
"NumericEquals": 200,
"Next": "LambdaFunction_MakePayment"
},
{
"Variable": "$.statusCode",
"NumericEquals": 400,
"Next": "Fail_Payment"
}
]
},
"LambdaFunction_MakePayment": {
"Type": "Task",
"Resource": "arn:aws:yyy",
"Parameters": {
"product_price": 1500,
"paid_price": 1500,
"product_id.$": "$.productID"
},
"Next": "CheckStatusFrom_Payment"
},
"CheckStatusFrom_Payment": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.statusCode",
"NumericEquals": 200,
"Next": "LambdaFunction_ThankYou"
},
{
"Variable": "$.statusCode",
"NumericEquals": 400,
"Next": "Fail_Payment"
}
]
},
"LambdaFunction_ThankYou": {
"Type": "Task",
"Resource": "arn:aws:lambda:zzz",
"Parameters": {
"product_name": "Television",
"product_id.$": "$.productID"
},
"Next": "Success_Payment"
},
"Success_Payment": {
"Type": "Pass",
"End": true
},
"Fail_Payment": {
"Type": "Fail"
}
}
}
RESULTPATHis not defined in Lambda task, thats why you are not able to access the variables?Resultfield sets *literal* (non-JSONPath) output. The good news is you probably don't need the Pass state. You probably want to set Lambda task'sResultSelectorand/orResultPath. I can't be more specific, because it's not clear what your actual/expected state inputs and outputs are.