You have an AWS API Gateway method with a request mapping template that extracts the 'userId' from the incoming JSON body and passes it as a path parameter to the backend. What will be the value of the path parameter 'userId' if the incoming request body is {"userId": "12345", "action": "login"}?
{
"userId": "$input.path('$.userId')"
}Think about how JSON path expressions extract values from the input JSON.
The mapping template uses $input.path('$.userId') which extracts the value of the 'userId' key from the JSON body. Since the input JSON has 'userId' set to '12345', the path parameter will be set to '12345'.
You want to map a backend error JSON response {"errorCode": "404", "message": "Not Found"} to a client response with status code 404 and a body containing only the message. Which response mapping template achieves this?
Look for the template that extracts the 'message' field correctly and formats the response body accordingly.
Option A correctly sets a variable to the root of the input JSON and then outputs only the 'message' field in the response body. Other options either extract wrong fields or format incorrectly.
You need to design an API Gateway setup that routes requests to different backend services based on a request header value, and applies different request mapping templates accordingly. Which architecture pattern is best?
Consider how API Gateway resources and methods can be configured to handle different request mappings and routing.
Option C uses multiple resources and methods within a single API Gateway, each with its own mapping templates and backend integrations. Request header-based mapping can be used to route requests to the correct resource. This is scalable and manageable.
If an API Gateway request mapping template does not properly validate or sanitize incoming JSON fields before passing them to the backend, what is the most likely security risk?
Think about what happens if malicious input is passed unchecked to backend services.
Improper validation or sanitization in request mapping can allow attackers to inject malicious code or queries, leading to injection attacks on backend services.
You have a complex backend response that requires multiple conditional transformations before sending to clients. What is the best practice to manage this complexity in API Gateway response mapping?
Consider maintainability and complexity of VTL templates versus external processing.
Complex transformations are better handled in Lambda functions where code is easier to write, test, and maintain. Embedding complex logic in VTL is error-prone and hard to maintain.