An organization enforces a standard error response schema where all HTTP error responses must return a JSON object containing a custom error ID and a descriptive message. A developer deployed a REST API in Amazon API Gateway protected by a Cognito User Pool authorizer. During testing, clients attempting to call the API without a valid token receive the default Gateway response `{"message":"Unauthorized"}`. Which configuration should the developer implement in API Gateway to return the custom error schema?
- Update the Gateway Response for the Unauthorized error type in API Gateway by configuring a mapping template for the application/json content type.Cevap
- BConfigure an integration response mapping template on the API Gateway method to catch the 401 status code and transform the payload.
- CReplace the Cognito User Pool authorizer with a custom Lambda authorizer, and return the custom JSON error payload in the response context when denying access.
- DEnable CORS on the API Gateway resources and add the custom error response schema under the Access-Control-Expose-Headers configuration.
Cevap
Update the Gateway Response for the Unauthorized error type in API Gateway by configuring a mapping template for the application/json content type.
Updating the Gateway Response for the Unauthorized error type is the correct approach. Gateway Responses are used to customize responses generated by API Gateway itself when a request does not reach the integration backend (such as authentication or authorization failures). By configuring a mapping template for the application/json content type, developers can format the response body to match any custom JSON error schema.
Adım Adım Çözüm
Anahtar Kavram
Amazon API Gateway Gateway Responses
Tahmini Süre:1m 30s