2

Is there a way not define the URL Query string parameters in both Method Request and Integration Request and pass the query string to HTTP Proxy?

For example, in case of https://{api id}-api.us-east-1.amazonaws.com/test/user?start=1&end=10

Query string 1. start 2. end

If I put URL Query string parameters in Method request and Integration request then I'm able to get both query strings. However, if I don't add them and make a request in postman then in the back end I'm not getting both query strings.

I want to get query strings without defining in Method Request and Integration Request. The reason is I don't want to type all parameters in hand if there are many.

Is there a way to do this?

I'm using HTTP Proxy and here is the template mapping that I'm using. (It's actually the Method Request passthrough drop down).

#set($allParams = $input.params())
{
"body-json" : "$input.json('$')",
"params" : {
#foreach($type in $allParams.keySet())
    #set($params = $allParams.get($type))
"$type" : {
    #foreach($paramName in $params.keySet())
    "$paramName" : "$util.escapeJavaScript($params.get($paramName))"
        #if($foreach.hasNext),#end
    #end
}
    #if($foreach.hasNext),#end
#end
},
"stage-variables" : {
#foreach($key in $stageVariables.keySet())
"$key" : "$util.escapeJavaScript($stageVariables.get($key))"
    #if($foreach.hasNext),#end
#end
},
"context" : {
    "account-id" : "$context.identity.accountId",
    "api-id" : "$context.apiId",
    "api-key" : "$context.identity.apiKey",
    "authorizer-principal-id" : "$context.authorizer.principalId",
    "caller" : "$context.identity.caller",
    "cognito-authentication-provider" : "$context.identity.cognitoAuthenticationProvider",
    "cognito-authentication-type" : "$context.identity.cognitoAuthenticationType",
    "cognito-identity-id" : "$context.identity.cognitoIdentityId",
    "cognito-identity-pool-id" : "$context.identity.cognitoIdentityPoolId",
    "http-method" : "$context.httpMethod",
    "stage" : "$context.stage",
    "source-ip" : "$context.identity.sourceIp",
    "user" : "$context.identity.user",
    "user-agent" : "$context.identity.userAgent",
    "user-arn" : "$context.identity.userArn",
    "request-id" : "$context.requestId",
    "resource-id" : "$context.resourceId",
    "resource-path" : "$context.resourcePath"
    }
}

2 Answers 2

2

As noted in the AWS Forums you must define all query string parameters explicitly. There is no passthrough support for query string parameters.

Sign up to request clarification or add additional context in comments.

Comments

1

You don't have to specify each parameter in the template, you can just do something like this in the mapping template to pass any parameters:

  "queryParams": {
    #foreach($param in $input.params().querystring.keySet())
    "$param": "$util.escapeJavaScript($input.params().querystring.get($param))" #if($foreach.hasNext),#end

    #end
  }

Also in the API Gateway UI now you can just select "Method Request passthrough" in the "Generate Template" dropdown and it will create a template for you that passes headers and parameters and other things without the need to specify specific properties that you want to pass through.

4 Comments

added template in integration request as you said but it doesn't work. I still don't get query strings if I don't specify in URL query string parameters. I'm not using Lambda function.
Can you add your mapping template to your question?
I just added mapping template and it's actually the one in the drop down as you said. In the back end, I'm not getting any query strings in the request.
@jgranda2 I haven't used API Gateway with an HTTP backend before, but I think your going to have to read the request data from the HTTP request body that API Gateway submits to your backend instead of looking for parameters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.