A developer is building a serverless application where Amazon API Gateway routes requests to a backend AWS Lambda function using a Lambda custom (non-proxy) integration. The Lambda function expects a JSON input containing a key named `userId`. However, client requests send this identifier as a query string parameter named `uid` (for example, `/users?uid=123`). How should the developer configure API Gateway to map the incoming query string parameter to the JSON payload format required by the Lambda function?
- In the Integration Request settings, add a mapping template for the application/json content type, and define the template body as {"userId": "$input.params('uid')"}.Cevap
- BIn the Integration Request settings, enable Lambda Proxy Integration to automatically convert the uid query string parameter into a root-level key named userId in the event payload.
- CConfigure a custom Lambda Authorizer for the Method Request to extract the uid query string parameter and rewrite it into the request body before the integration takes place.
- DEnable Lambda Proxy Integration and configure a Method Response mapping template to transform the request payload format before it is forwarded to the backend Lambda function.
Cevap
In the Integration Request settings, add a mapping template for the application/json content type, and define the template body as {"userId": "$input.params('uid')"}.
In a Lambda custom (non-proxy) integration, request mapping templates are used to shape the payload before it is dispatched to the backend. Using Velocity Template Language (VTL), the developer can define a template for the application/json content type. The expression $input.params('uid') extracts the value of the uid query string parameter and maps it to the userId key in the constructed JSON payload.
Adım Adım Çözüm
Anahtar Kavram
Request transformation using API Gateway mapping templates for Lambda custom integrations.