Select specific portions of the raw input using the InputPath filter
Use the InputPath
filter to select a specific portion of the input payload.
If you don't specify InputPath
, its value defaults to $
, which causes the state's task to refer to the entire raw input instead of a specific portion.
To learn how to use the InputPath filter, perform the following steps:
Step 1: Create a state machine
Important
Ensure that your state machine is under the same Amazon account and Region as the Lambda function you created earlier.
-
Use the
Parallel
state example you learned about in Tutorial 4 to create a new state machine. Make sure your workflow prototype looks similar to the following prototype. -
Configure the integrations for the
check-identity
andcheck-address
Lambda functions. For information about creating the Lambda functions and using them in your state machine, see Step 1: Create the Lambda functions to perform the required checks and Step 2: Update the workflow – Add parallel tasks to be performed. -
For Payload, make sure you keep the default selection of Use state input as payload.
-
Choose Next and then do the steps 1 through 3 in Step 1: Save the state machine of Tutorial 5 to create a new state machine. For this tutorial, name your state machine
WorkflowInputOutput
.
Step 2: Run the state machine
-
On the WorkflowInputOutput page, choose Start execution.
-
(Optional) To identify your execution, you can specify a name for it in the Name box. By default, Step Functions automatically generates a unique execution name.
Note
Step Functions allows you to create names for state machines, executions, activities, and labels that contain non-ASCII characters. These non-ASCII names don't work with Amazon CloudWatch. To ensure that you can track CloudWatch metrics, choose a name that uses only ASCII characters.
-
In the Input area, add the following JSON data as the execution input.
{ "data": { "firstname": "Jane", "lastname": "Doe", "identity": { "email": "jdoe@example.com", "ssn": "123-45-6789" }, "address": { "street": "123 Main St", "city": "Columbus", "state": "OH", "zip": "43219" } } }
-
Choose Start execution.
-
The state machine execution results in an error because you’ve not specified what parts of the execution input the
check-identity
andcheck-address
Lambda functions must use to perform the required identity and address verification. -
Continue to Step 3 of this tutorial to fix the error.
Step 3: Use the InputPath
filter to select specific parts of an execution input
-
On the Execution Details page, choose Edit state machine.
-
To verify the applicant’s identity as mentioned in the execution input provided in Step 2: Run the state machine, edit the Verify identity task definition as follows:
... { "StartAt": "Verify identity", "States": { "Verify identity": { "Type": "Task", "Resource": "arn:aws-cn:states:::lambda:invoke", "InputPath": "$.data.identity", "Parameters": { "Payload.$": "$", "FunctionName": "arn:aws-cn:lambda:us-west-2:123456789012:function:check-identity:$LATEST" }, "End": true } } } ...
Consequently, the following JSON data becomes available as input for the
check-identity
function.{ "email": "jdoe@example.com", "ssn": "123-45-6789" }
-
To verify the applicant’s address as mentioned in the execution input, edit the
Verify address
task definition as follows:... { "StartAt": "Verify address", "States": { "Verify address": { "Type": "Task", "Resource": "arn:aws:states:::lambda:invoke", "InputPath": "$.data.address", "Parameters": { "Payload.$": "$", "FunctionName": "arn:aws:lambda:us-east-1:123456789012:function:check-address:$LATEST" }, "End": true } } } ...
Consequently, the following JSON data becomes available as input for the
check-address
function.{ "street": "123 Main St", "city": "Columbus", "state": "OH", "zip": "43219" }
-
Choose Start execution. The state machine execution now completes successfully.