Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Api Gateway hardcoded query string parameter

I am looking to wrap a third party resource, to expose it without the access token that is sent as a query parameter.

For this reason, I thought I could use the API gateway.

I found how to have mapped path and query parameters, which are proxyed from the request itself.

But is it possible to somehow hardcode the access token inside the API gateway, to be passed onto the destination, so the users won't have to include it in their request?

Or my only option is to make a Lambda for this purpose...?

like image 550
Wilhelm Sorban Avatar asked May 03 '26 17:05

Wilhelm Sorban


2 Answers

I used terraform to create these kind of resources. here is an example of a api integration using terraform:

resource "aws_api_gateway_integration" "api_store_get_integration" {
  rest_api_id               = "${aws_api_gateway_rest_api.service_api.id}"
  resource_id               = "${aws_api_gateway_resource.store.id}"
  http_method               = "${aws_api_gateway_method.store_get.http_method}"
  integration_http_method   = "GET"
  type                      = "HTTP_PROXY"
  uri                       = "${var.yext_base_url}entities"
  passthrough_behavior      = "WHEN_NO_MATCH"
  request_parameters = {
    "integration.request.header.api-key"      = "'${var.yext_api_key}'",
    "integration.request.header.content-type" = "'application/json'",
    "integration.request.querystring.filter"  = "method.request.querystring.filter",
    "integration.request.querystring.v"       = "'20191001'"
  }
}

explaining it:

  1. The api will receive a request
  2. It will forward the get request to a defined uri: var.yext_base_url/entities
  3. It will append api-key header to the request with a variable passed to terraform
  4. It will append content-type header to the request with a static value
  5. It will append the query param v with the static value '20191001'

If you don't know about terraform, it is a tool that reads this document and send requests to AWS to create the resources in the way that you defined them. In the case of the snippet above, terraform will receive two variables vat.yext_base_url and var.yext_api_key, will concatenate their values in the configuration and create the resources in AWS.

I don't know what you're using, but in your case you will need to find the place to change the configurations for the integration request. Try to research a little and if you don't find it I can guide you again based on your deployment model.

like image 185
Gustavo Tavares Avatar answered May 05 '26 10:05

Gustavo Tavares


Don't know if you ever solved this, but for anyone coming across this question, you can do this in the console if you enter the static value in single quotes: enter image description here

The quotes are removed from the parameter when the integration request is made.

enter image description here

like image 42
Daniel Avatar answered May 05 '26 09:05

Daniel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!