amazon-web-servicesaws-api-gatewayaws-step-functions

Cannot add variable from context on QueryParameters on Step Function API Gateway call


I'm trying two consecutive API Gateway calls from a Step Function, using values from the first result on the second. I tried already on a POST call and it worked, but now I can't do it on a GET call. This is my step function:

{
  "Comment": "A Hello World example of the Amazon States Language using Pass states",
  "StartAt": "Api Call",
  "States": {
    "Api Call": {
      "Type": "Task",
      "Resource": "arn:aws:states:::apigateway:invoke",
      "Parameters": {
        "ApiEndpoint": "***************.us-east-1.amazonaws.com",
        "Method": "GET",
        "Path": "universities",
        "RequestBody": {},
        "AuthType": "NO_AUTH"
      },
      "ResultSelector": {
        "logWord.$": "$.StatusText"
      },
      "Next": "Api Call 2"
    },
    "Api Call 2": {
      "Type": "Task",
      "Resource": "arn:aws:states:::apigateway:invoke",
      "Parameters": {
        "ApiEndpoint": "***************.us-east-1.amazonaws.com",
        "Method": "GET",
        "Path": "logging",
        "Headers": { 
            "Content-Type": ["application/json"] 
        },
        "QueryParameters": {
          "logWord.$": "$.logWord"
        },
        "AuthType": "NO_AUTH"
      },
      "End": true
    }
  }
}

The error that I get is the following:

{
  "error": "States.Runtime",
  "cause": "An error occurred while executing the state 'Api Call 2' (entered at the event id #7). The Parameters '{\"ApiEndpoint\":\"***************.us-east-1.amazonaws.com\",\"Method\":\"GET\",\"Path\":\"logging\",\"Headers\":{\"Content-Type\":[\"application/json\"]},\"QueryParameters\":{\"logWord\":\"OK\"},\"AuthType\":\"NO_AUTH\"}' could not be used to start the Task: [The value of the field 'QueryParameters' has an invalid format]"
}

According to the documentation, query parameters should be between brackets, but if I'm using a context variable I can't put the brackets. The console doesn't allow me to even save (The value for the field 'logWord.$' must be a STRING that contains a JSONPath but was an ARRAY).

If anyone knows how to make GET call using context variables would be greatly appreciated.


Solution

  • Looks like QueryParameters wants a list of strings. Use the States.Array intrinsic function to convert your interpolated string to a [string] list.

    "QueryParameters": {
        "logWord.$": "States.Array($.logWord)" // ["OK"]
      },