You are developing a REST API in Amazon API Gateway.
The API integrates with a Lambda Function.
You found that when clients hit the API using an unsupported method, the API Gateway has returned a Missing Authentication Token (403) response.
As the response does not provide much information, you want to customize the response.
For example, you want to change the error code to 404 and add some custom HTTP headers.
How would you implement this?
Click on the arrows to vote for the correct answer
A. B. C. D.Correct Answer - A.
Users can customize the gateway response using the API Gateway console according to
https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-gateway-response-using-the-console.html.Option A is CORRECT: Users can select the particular Missing Authentication Token 403 gateway response under the API and customize it as below screenshot:
Option B is incorrect: In this scenario, it needs to modify the default gateway response.
The integration response of the API method should not be changed.
Option C is incorrect: Because in the AWS API Gateway console, users cannot forward a gateway response to another.
Instead, the status code, headers and bodies should be customized.
Option D is incorrect: Similar to option.
B.
The method configuration should not be modified.
It does not change the API Gateway behavior when clients hit an unsupported method.
The correct answer is A. In the AWS API Gateway console, choose Gateway Responses under the API and select the 403 response. Add custom headers and modify the response status code to 404.
When a client hits an API using an unsupported method, the API Gateway returns a Missing Authentication Token (403) response. This response does not provide much information, so you may want to customize it. Specifically, you want to change the error code to 404 and add some custom HTTP headers.
To implement this, you need to customize the Gateway Response. Gateway Responses are a set of HTTP responses that can be returned by API Gateway when there is an error or when a request does not match any of the defined API methods.
Here are the steps to customize the Gateway Response:
After you have customized the Gateway Response, API Gateway will return the modified response whenever a client hits the API using an unsupported method.
Option B is incorrect because modifying the integration response would only modify the response returned from the Lambda function. It would not modify the Gateway Response returned by API Gateway.
Option C is incorrect because forwarding the Missing Authentication Token 403 response to an HTTP 404 Not Found response would not be a valid solution. The client is not requesting a resource that is not found, but rather using an unsupported HTTP method.
Option D is also incorrect because forwarding the 403 response to a 404 response is not a valid solution. It does not accurately represent the error that occurred, and it could cause confusion for clients consuming the API. Additionally, the custom headers should be added to the Gateway Response, not the forwarded response.