Soru

Zorluk: Çok zorAPI Development and Integration with Amazon API Gateway

A developer is designing a REST API using Amazon API Gateway that integrates directly with an Amazon DynamoDB table using an AWS service integration. The API needs to expose a POST method to insert customer records. To optimize throughput and performance, the developer wants to ensure that:

1. Incoming payloads are validated against a specific JSON schema, and requests with invalid structures are rejected with a 400400 Bad Request response before the integration is invoked.
2. The DynamoDB response, which contains the raw database attributes, is transformed into a simplified, customer-facing JSON format before being returned to the client.

Which two configuration steps must the developer perform in API Gateway to satisfy these requirements? (Select TWO.)

  1. Create a model representing the schema of the payload, assign the model to the method request, and enable request validation for the request body in the method settings.Cevap
  2. Configure an integration response for the 200200 HTTP status code, and write a mapping template using Velocity Template Language (VTL) to transform the DynamoDB response into the desired format.Cevap
  3. C
    Deploy a custom Lambda authorizer to parse the incoming request body, validate the schema structure, and return an IAM policy denying the request if attributes are missing.
  4. D
    Use a Lambda proxy integration with API Gateway to automatically route the client request directly to DynamoDB and apply the required VTL mapping templates.
  5. E
    Configure a method response mapping template for the 200200 status code to directly parse the DynamoDB return attributes and output the client-facing JSON.

Cevap

To reject requests with invalid structures before the integration is invoked, the developer should create a model representing the schema of the payload, assign it to the method request, and enable request validation for the request body. To transform the DynamoDB response into a simplified, customer-facing JSON format, the developer should configure an integration response for the 200 HTTP status code and write a Velocity Template Language (VTL) mapping template.
To automatically reject malformed payloads before invoking the backend, API Gateway's Request Validator must be used in conjunction with a defined JSON schema model linked to the method request. To transform the response of a non-proxy AWS service integration (such as DynamoDB), a VTL mapping template must be defined within the integration response for the 200 HTTP status code. Together, these steps satisfy both validation and payload transformation requirements without invoking intermediate code.

Adım Adım Çözüm

1
Define the request schema model
A JSON schema model is created in API Gateway that specifies the required attributes and types for the incoming customer record.
This establishes the structure against which incoming payloads will be validated.
2
Enable request validation on the Method Request
The request validator is configured to check the request body, and the schema model is associated with the POST method request.
This ensures that API Gateway intercepts invalid payloads and immediately returns a 400 Bad Request error to the client, preventing the integration from being called.
3
Configure the Integration Response mapping template
An integration response for the 200 status code is created, containing a VTL template to parse the raw DynamoDB return attributes.
Since this is an AWS service integration (non-proxy), response transformation must occur at the Integration Response stage using VTL to map DynamoDB attributes to clean customer-facing JSON.

Anahtar Kavram

API Gateway input validation and non-proxy integration response mapping templates
Bu soruyu puanla