An organization has a REST API exposed via Amazon API Gateway that routes client requests to a backend AWS Lambda function. To reduce Lambda invocation costs, the developer needs to validate that incoming JSON request payloads contain a required `accountId` string field before the requests are forwarded to the backend. If a request is invalid, API Gateway must return an HTTP 400 Bad Request response directly to the client without invoking the backend function.
Which configuration steps should the developer perform to meet these requirements?
- Create a Model using JSON Schema to define the required `accountId` property, associate it with the method request body, and set the Method Request validator to validate the request body.Cevap
- BConfigure a Lambda Proxy integration and use a Velocity Template Language (VTL) mapping template in the Integration Request to inspect the payload and reject invalid requests.
- CConfigure a Lambda Authorizer to parse the incoming request body, validate the schema structure, and return an Allow policy only if the `accountId` field is present.
- DSet up a custom Gateway Response mapping template for the default Integration Response that validates the incoming payload before executing the integration.
Cevap
Create a Model using JSON Schema to define the required `accountId` property, associate it with the method request body, and set the Method Request validator to validate the request body.
The correct option is to define a Model using JSON Schema, associate it with the request body in the Method Request settings, and enable the Request Validator to validate the request body. When request validation is enabled, API Gateway validates the request payload before forwarding it to the integration backend. If the validation fails, API Gateway immediately returns a 400 Bad Request response without invoking the integration (the backend Lambda function), minimizing Lambda executions and costs.
Adım Adım Çözüm
Anahtar Kavram
API Gateway Request Validation with Models
Tahmini Süre:2m 0s