A developer is configuring an Amazon API Gateway REST API with an HTTP custom (non-proxy) integration that connects to an on-premises backend service. The backend service always returns an HTTP 200 OK status code, even when an application-level error occurs. When such an error occurs, the backend JSON response body contains the field "errorCode": "INVALID_PARAMETERS". The developer needs the API Gateway to return an HTTP 400 Bad Request status code to the client instead of HTTP 200 OK when this error is present.
Which configuration strategy should the developer use to achieve this?
- Deploy an intermediate AWS Lambda function using Lambda integration to call the backend service, inspect the response payload, and return the appropriate HTTP status code to API Gateway.Cevap
- BCreate a Velocity Template Language (VTL) mapping template within the 200 OK Integration Response to dynamically override the method response status code to 400 if the payload contains the error code.
- CCreate an Integration Response with an HTTP status regex pattern of .*INVALID_PARAMETERS.* to match the backend response body and map it to the HTTP 400 Method Response.
- DConfigure a Lambda Authorizer in API Gateway to intercept the backend response, inspect the JSON payload, and return a response policy that overrides the HTTP status code to 400.
Cevap
Deploy an intermediate AWS Lambda function using Lambda integration to call the backend service, inspect the response payload, and return the appropriate HTTP status code to API Gateway.
The correct strategy is to deploy an intermediate AWS Lambda function. Because the backend service always returns an HTTP 200 OK status code, API Gateway cannot natively select a different integration response based on the JSON body content. By routing the request through a Lambda function, the function can inspect the legacy backend response body and return a response that allows API Gateway to map it to an HTTP 400 Bad Request client response.
Adım Adım Çözüm
Anahtar Kavram
API Gateway custom integration response mapping constraints