AWS API Gateway expects the request URL to be encoded twice

Viewed 648

My API is a request that can potentially have spaces in the pathParameters.

/data/{id}/hello/{Some message with a space}. A sample request would be /data/23/hello/Say%20Hi

My angular code from the frontend encodes the request URL that is sent out to the AWS API Gateway but I get the following error.

`The Canonical String for this request should have been
'GET
/data/23/hello/Sayr%2520Hi`

My API gateway has a velocity template the decodes the parameters using $util.urlDecode()

1 Answers

I'm facing the same problem. I've been stuck for a day.

If you are using HttpApi it cannot be solved.

Nevertheless, if you use RestApi I managed to make this work.

Specifically, you should use the URL Path Parameters.

You should:

  1. Add a resource containing the /{variable}
  2. Add a Url Path Parameter in the Integration Request Configuration with name variable and mapped from method.request.path.variable

Notice that the solution may depend on the integration type that you are using.

In the screenshot below you can see how I'm redirecting all the received traffic to a NetworkLoadBalancer. The resource has the variable /{proxy+}, the endpoint URL has the {proxy}, and, in the URL Path Parameters, I've configured the mapping method.request.path.proxy.

enter image description here

Related