Question #607
A developer is testing error handling for a mobile app that interacts with an Amazon API Gateway REST API. The developer needs to simulate various HTTP error responses (e.g., 400, 500) during testing without triggering the actual backend service.
Which approach fulfills these requirements with the LEAST operational overhead?
Deploy an AWS Lambda function with error-throwing logic. Integrate it with API Gateway using proxy integration.
Set up an Amazon ECS cluster with containers that return predefined error codes. Configure API Gateway to route to the ECS service.
Modify the API Gateway resource methods to return hardcoded error responses using gateway responses.
Use API Gateway mock integrations with context variables in mapping templates to dynamically generate error responses.
Explanation
The correct answer is D because:
- Mock integrations enable API Gateway to return predefined responses without invoking backend services. By leveraging context variables in mapping templates, developers can dynamically generate error codes (e.g., 400, 500) based on test parameters (e.g., query strings or headers). This approach requires no backend deployment, reducing operational overhead.
- Why other options are incorrect:
- A: Deploying a Lambda function adds operational complexity (code maintenance, permissions, versioning).
- B: Setting up ECS clusters involves significant infrastructure management (containers, scaling, networking).
- C: Gateway responses handle predefined API Gateway errors (e.g., 403, 504) but cannot dynamically simulate arbitrary error codes for testing.
Key Points:
- Use mock integrations + mapping templates for lightweight error simulation.
- Avoid backend dependencies (Lambda/ECS) when testing API error handling.
Answer
The correct answer is: D