How to send json payload as HTTP OPTIONS response body? - amazon-web-services

The HTTP OPTIONS method is supposedly used to determine what other methods the server supports on a given resource. Given that, I have questions:
I have a GET API having certain parameters and I want to provide some information about the parameters (ex:their usage,type) in the preflight request.
Suppose, I have the following endpoint:
/v1/pets/?limit=10&page=1&birth_year=2013
and I want to provide the usage information (format,type,etc) about the parameters limit,page and birth_year in the OPTIONS response body.
Questions
Is it possible to send a json payload in response to OPTIONS request?
How can that be achieved using AWS API Gateway?

Related

AWS API Gateway Not Passing Custom Headers

I have an API Gateway request where I am passing a custom header that is not being passed into the Lambda which is its target. First and foremost, I checked the verbose logs for the API Gateway Instance and can see the custom header called x-treasury-system being passed in and present in Method request headers:
But it is not present in Endpoint request headers:
Which is why I think its not ending up in the Lambda. I have the following header mappings setup - In the Method Request:
And in the Integration Request:
What am I missing? It seems that all is in order to pass that header, I double checked in lambda logs when printing out the headers that it is for sure not coming in.

How do I respond with a request header in AWS API Gateway

I have a POST request coming in with a header that I need to play back with the response (Example: "Validation: 123").
The integration returns synchronously, immediately.
The header is entirely non-functional and so doesn't need to be passed through to my integration. It just needs to be passed back with the response to the inbound request.
I am trying to do this by mapping the headers from the method request through to the method response, or via the integration request/response.
For example, I'd like to set the header mapping for the integration response to method.request.header.Validation (ie, identically to the integration request mapping). However, this is disallowed.
Is this the right approach?
This is a limitation of AWS API Gateway.

Response depends on Request Content-Type

in my Integration Request I have Body Mapping Tempates for application/xml, application/json (the same template body - reads URL parameters and create JSON body as lambda input).
Client is requesting API with application/json or application/xml. How to make response body format depending on request Content-Type in API Gateway only?
Regards,
Radek
Create ANY integration and handle everything with Lambda. You can avoid all the mappings and handle everything in code and we found that much easier.
More details here on ANY Integration,
https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-set-up-simple-proxy.html
Hope it helps.

Evaluate requests in the API Gateway

Can the API Gateway evaluate requests and route or return errors (not 200 statuses) on specific parameters?
What I want to achieve here is to NOT have millions of requests hitting our backend API since we already know (by evaluating the parameters) that we are not interested in returning responses on all requests but only a few percent.
I gave set up an API Proxy in the API Gateway with a complete set of requests, responses and backend.
The proxy is fully operational and up and running with throttling etc. What I would like is for the API Gateway to evaluate the requests querystring and depending on the values of certain parameters take different actions?
Let's say the complete URL and querystring is:
https://abc123.execute-api.eu-central-1.amazonaws.com/prod?param1=a&param2=b&param3=c
Now depending on the values of param1, param2 and param3 I might want to:
Forward the request to my actual API and return a response back to the client.
Drop the request OR return an empty (or templated) response with a specific HTTP-status (404, 503 etc - exact value not that important).
Is this achievable with the API Gateway or do I need to actually set up a host with a reverse proxy and let that handle this logic?
Request parameter and model validation has been a longstanding feature request and we are actively working on it. We'll update this post with more details when the feature has launched.
Update: Request parameter and body validation is now available as of early April 2017. see more details on this blog post.

How to set input mapping for all requests, not just application/json

Looking at the examples for AWS API Gateway in order to map a querystring to the Lambda function it shows examples of creating a template map for application/json in the integration request. How do I create a template for all requests no matter the Content-Type? I want it to fire the Lambda with the querystring params regardless of the Content-Type in the request.
This is not possible at the moment. There is no documented wild card available.
"application/json" is the default content type. This is used if no content type is specified in the request (source: https://forums.aws.amazon.com/thread.jspa?threadID=215471).