amazon-web-servicesamazon-ecsaws-step-functions

Consuming json input for ECS container configuration in AWS step functions


I am facing an issue when trying to access attributes of the json input that is passed to my run ECS task in my step function. The json input has the following structure.

enter image description here

I am trying to pass some of the attributes as command line parameters and to set some as environment variables. Below is my ECS task configuration in my step function.

enter image description here

When I run the ECS task the values are getting pass as string Ex: "$.lambdaResult.body.productId" and not the actual value in the json. I tried setting up the values of the environment variables as "Value.$": "$.lambdaResult.body.totalPrice" But then it gives me the following error when deploying the step function.

"Invalid State Machine Definition: 'SCHEMA_VALIDATION_FAILED: The value for the field 'Value.$' must be a valid JSONPath or a valid intrinsic function call at /States/RunCreateOrderECSTask/Parameters'

What is the correct way of passing the json values as command line arguments and setting them up as environment variables . I am using a spring boot container so what ever in the Command [] is getting passed in to the application as parameters.


Solution

  • I see a couple of issues with your workflow definition.

    First, you have not suffixed the keys with .$ where you are providing a JSONPath.

    {
      "Name": "UNIT_PRICE",
      "Value": "$.lambdaResult.body.unitPrice"
    }
    

    should be

    {
      "Name": "UNIT_PRICE",
      "Value.$": "$.lambdaResult.body.unitPrice"
    }
    

    Second, when you want to provide an Array, you need to use the States.Array Intrinsic Function. For example:

    "Command.$": "States.Array($.lambdaResult.body.productId,$.lambdaResult.body.productDescription,$.lambdaResult.body.productType)"