1
votes

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...?

2

2 Answers

2
votes

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.

0
votes

Yes, it is! I did this a lot.

You'll need to create a REST API and use HTTP_PROXY integration type.

When you configure the integration, you can define the uri and request parameters that will be sent to your integration endpoint. In that case you can add query parameters to the request as static values instead of mapping from the request received by the API.

You can find more information here and here.