Alex
Alex

Reputation: 51

How to set the Headers.$ input for Step functions to invoke api gateway?

When I used the step function to invoke API Gateway, I filled the "Headers.$": "$.input.headers", but when I test it, it gives me could not be used to start the Task: [The value of the field 'Headers' has an invalid format] every time, I tried this

"input": {
        "headers": {
            "Authorization": "abcd",
            "Content-Type": "application-json"
        }
    }

it doesn't work, could anyone give me an example of this headers field?

Really appreciate!

Upvotes: 3

Views: 3003

Answers (1)

yamatatsu
yamatatsu

Reputation: 61

I met same problem. And I resolved it as following.

First, we cannot use Authorization header and other some headers as the note of this documentation. So we should use a custom header. It is mapped to Authorization header in API Gateway.

Next, from what I've tried, we probably should use array format in value of Headers. So you can write as following:

"input": {
  "headers": {
    "x-Authorization": ["abcd"],
    "Content-Type": ["application-json"]
  }
}

and I use intrinsic functions as following:

"Headers":{
  "x-Authorization.$":"States.Array(States.Format('Bearer {}', $.SecretOutput.Token))"
}

And finally, we should set two configration in API Gateway.

  1. Set request parameter mapping to map method.request.header.x-Authorization to Authorization header. documentation
  2. Set accepting custom request header x-Authorization. documentation

Upvotes: 6

Related Questions