Mapping request query params to request body in AWS API Gateway

Viewed 128

I am having some trouble with API gateway request mapping.

In the gateway integration request I did a VPC link with internal NLB.

The gateway url is taking the request parameters in query string where as my backend server requires parameters to be passed in request body.

I defined a model for request body, and in the Method Execution mapping template I used generate template to map those querystring parameters into request body which looks as follows

#set($inputRoot = $input.path('$'))
{
  "countA" : $input.params().querystring.country1,
  "countB" : $input.params().querystring.country2,
  "languages" : $input.params().querystring.langs,
  "limit" : $input.params().querystring.limit,
  "skip" : $input.params().querystring.skip
}

However when I go to test the request from method execution the request body does not seems to be passed correctly to my backend server.

The logs on my server returns an empty body in request. And looking at the gateway logs I see that parameters are being mapped correctly to the body of the request but somehow they are not being passed to the backend server as my response is always missing parameters.

    Tue May 12 09:59:45 UTC 2020 : Endpoint request URI: http://requesturl
    Tue May 12 09:59:45 UTC 2020 : Endpoint request headers: {x-amzn-apigateway-api-id=u5pfio0upd, Accept=application/json, User-Agent=AmazonAPIGateway_id, Host=requesturl.elb.eu-west-1.amazonaws.com, X-Amzn-Trace-Id=Root=1-3wba7391-134d9978712e77d221c675f4, Content-Type=application/json}        
    Tue May 12 09:59:45 UTC 2020 : Endpoint request body after transformations: {
      "countA" : ir,
      "countB" : uk,
      "languages" : en,
      "limit" : 10,
      "skip" : 0
    }
    Tue May 12 09:59:45 UTC 2020 : Sending request to http://requestUrl
    Tue May 12 09:59:45 UTC 2020 : Received response. Status: 400, Integration latency: 17 ms

I am unable to figure out the issue. I even tried using 'Method Request Passthrough' to generate template and setting parameters in body-json, I get same results.

I have not been able to find a resource that explains if this can be done or not and how.

I have tested the mapping from query strings to query strings and never ran into such issue.

Here, I could use some guidance on what I am doing wrong.

0 Answers
Related