3

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

3 Answers 3

4

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.

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

3 Comments

Thanks for taking the time, but I'm unsure why you are assuming I'm using Terraform, and besides, in your first answer, there is nothing that mentions this. I am using plain old AWS API Gateway configuration. Which I can configure either using OpenAPI, or by the graphical interface. I simply want to proxy a GET api through the Gateway, onto another GET request, that has an access token. I want to have the token hardcoded in API gateway, and pass it as a query param, to the target URL.
Api Gateway will not let me achieve this, because it expects a mapped querystring value, that is provided in the proxy request.
I didn't assumed that you would be using terraform. I just explained to you that I'm using and showed to you what the values must be changed. In summary you must find where you are configuring the querystring in your deployment model and change it. just a hint: if you find the correct place, you can pass them as static values instead of mapping...
2

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

Comments

0

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.

2 Comments

Sorry, but whenever I try to set a static value, instead of an actual mapping, I get an error, and it won't let me save. Would you be so kind to send me a screenshot or something, of exactly where to do it, and what value you are adding, that will let you save? The AWS documentation didn't seem to help me too much :(
the text is to big to comment, I will add another answer

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.