I am trying to use AWS API Gateway to proxy requests to some REST endpoints I have running in docker containers. I set up my API Gateway method for integration type HTTP and checked 'Use HTTP Proxy integration', But this is not simply proxying my requests, it strippes out the path parameters, query string parameters and body, and makes me map them to something.
Am I missing something, I don't want API gateway transforming my request I just want it to proxy it back to my internal REST endpoints.
FYI I am using a swagger doc to generate the API Gateway structure (their UI is quite annoying)
I read about {proxy+} endpoints which sound like what I want, but how do I define swagger docs about a certain endpoint action, or have granular apikey and authorizors on my endpoints?
You can set authorization only for resources and methods
. For example, we have the following API structure:
/
/test
GET (1)
PUT
/test/new (2)
ANY
/example/{proxy+}
GET (3)
1) For method
site.com/test endpoint
in GET method if you try to use the same key in PUT method you cath error.
2) For resource
site.com/test/new endpoint
in all methods in /test/new, but if you try to GET on /test/new/new2 you cath the error.
3) For resource(with proxy)
site.com/example/{proxy+} endpoint
You can auth to any example/* path.
Related
I'm looking after solution where AWS Api Gateway changes method endpoint Url dynamically.
I am familiar with stage variables and in Integration request I can change endpoint per method like (https://${stageVariables.Url}/api/DoSomething).
What I need is that information how parse endpoint is included in requests.
https://${RequestData.Url}/api/DoSomething
I have same Api in different locations and to implement centralized Api keys and logging services I try to forward all traffic through this one Api Gateway.
After first request client gets its endpoint information, but I don't know how to solve that clients next requests to Gateway should forward to that endpoint which client get earlier.
I got an answer from AWS support. They told that I have to make a lambda function to process all requests or just use Stage variables.
I have a custom domain set up in AWS API Gateway. My intention is to use "API mappings" to send traffic for different API versions to their respective API Gateways, e.g.:
GET https://example.com/v1/foo is sent to an API gateway "APIv1" ($default stage) via an API mapping on the custom domain with path="v1".
GET https://example.com/v2/foo is sent to an API gateway "APIv2" ($default stage) via an API mapping on the custom domain with path="v2" (not shown)
The HTTP APIs themselves are configured with a single route /{proxy+} and an integration that sends requests to a private ALB:
This setup works fine as far as routing traffic goes, but the problem is that when the request makes it to the actual application, the routes the application receives are like /v1/foo instead of just /foo, which is what the app is expecting.
I've played around with different route matching and parameter mapping (of which I can find almost no examples for my use case) to no avail.
I could change my app code to match the routes that AWS is sending, but the entire point of this was to handle versioning using my AWS stack and not app code. Do I have another option?
If you create a resource called /foo and the proxy resource inside it, when you set integration you can define which path to pass and the {proxy} will have just the part after /foo, ignoring the v1 entirely.
See an example below.
In this case it is ignoring everything before v1 and it is also rewriting the integration to /api/{proxy}.
It will receive a request as GET https://example.com/abc/xyz/v1/foo and will forward to backend as GET https://example.com/api/foo.
Update
It can't be done via VPC Link, but we can use public ALB almost like private, like the explanation below.
It explain about CloudFront, but the same is valid for API Gateway.
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/restrict-access-to-load-balancer.html
It's totally possible. You just need to use parameters mapping for this. Using the AWS UI it would be:
I would like to proxy the incoming requests to different endpoints based on a request header received in the request.
In AWS API gateway, I can set up different endpoints as separate stage variables but at integration >> Endpoint URL setting, I would like to pick the stage variable based on the value of request header value.
For example:
if header value is brand-id: abc then request should be proxied to abc.test.com
if header value is brand-id: pqr then request should be proxied to pqr.test.com
I'm expecting something like this in "Endpoint URL" value:
http://${stageVariables.${method.request.header.brand-id}}/
Any help to achieve this would be appreciated.
AFAIK this is not possible on the API Gateway level. Option is to do the mapping on the lambda integration level.
You can use Lambda Proxy Integration to achieve the similar behavior:
Create your required set of API's.
Create a proxy endpoint that will pass everything to the Lambda Function.
Inside the Lambda Function decide on the basis of headers to call the respective endpoints and pass the required data from the payload you got.
Return the response as it is from the API you called.
You can use python's adapter pattern, or string parameter formatting to save yourself from the clutter of if and else conditions. You can also consider calling Lambdas directly from your proxy Lambda with RequestResponse invoke, that may save yourself some time caused by the extra layer of API Gateway.
I have an AWS API Gateway endpoint(Invoke URL),
I created a Custom Domain, to map the Domain with my API Gateway as the Invoke URL is made of non user friendly characters,
I mapped the Custom Domain with the API Gateway,
I followed these steps -
http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-custom-domains.html
Both the Default Invoke URL and Custom Domain endpoint are responding correct data,
So far so good.
On further testing I found out that as my default Invoke URL had Caching enabled on it,
I enabled API Gateway cache by following this -
http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-caching.html
The response was in miliseconds,
Weirdly the Custom Domian mapped endpoint is responding slower and looks like it is not Caching the previous responses, even though Caching is properly enabled on the API Gateway,
I need to Enable Caching on the Custom Domian as well,
Do I need to add CloudFront in front of the API Gateway or something?
How do I achieve this?
I am not able to find my Invoke URL in CloudFront origin,
I couldn't understand these solutions either -
1. http://www.davekonopka.com/2016/api-gateway-domain.html
2. How do you add CloudFront in front of API Gateway
Is there a way to configure the HTTP Proxy for all methods of resource at once so
FIRST:
GET,POST,PUT,DELETE of /v1/resource should all be forwarded to http://api.com/resource/{id}
If that is possible can I still map:
GET /v1/resource/schema to an S3 ?
or do i have to define them one by one.
The emergency way to save some time is probably to generate a swagger API documentation and create the API Gateway setup of it.
API Gateway doesn't support to set up multiple methods for one resource at once. As you already mentioned, you could create a Swagger template and use the API Gateway Importer tool (https://github.com/awslabs/aws-apigateway-importer).
Best,
Jurgen