Search code examples
aws-step-functions

How to build query parameters for api gateway from input path step function?


I am trying to build step function that invokes my api gateway proxy. I am unable to pass input to query parameters. What is the correct syntax and can it be done?

I've tried "$.zzId" but it does not replace it with the input value.

        "Branches": [
        {
          "StartAt": "Get Content",
          "States": {
            "Get Content": {
              "Type": "Task",
              "Resource": "arn:aws:states:::apigateway:invoke",
              "Parameters": {
                "ApiEndpoint": "zcxzscaw.execute-api.us-east-1.amazonaws.com",
                "Method": "GET",
                "Headers": {},
                "Path": "/bmx/content",
                "zzId" : "$.zzId" // <-- this resolves it with correct value but fails to execute step function because it is invalid attribute, but at least I know that it is correct path
                "QueryParameters": {
                  "zzId": [
                    "$.zzId" // <-- this does not do anything 
                  ]
                },
                "RequestBody": {},
                "AuthType": "NO_AUTH"
              },
              "TimeoutSeconds": 3,
              "End": true
            }
          }
        }

Solution

  • Put a .$ suffix on keys you want to Step Functions to substitute the values. Substitutions expect a string value, so use the States.Array intrinsic function to wrap the value in an array.

    GIVEN:

    "QueryParameters": {
        "zzId.$": "States.Array($.zzId)"
    },
    

    WHEN the input is {"zzId": "Hello world"}

    THEN the output is:

    "QueryParameters": {
        "zzId": ["Hello world"]
    },