DVA-C02 Question 250
Single answerYou are developing a serverless application using AWS Lambda and API Gateway. To ensure reliable integration testing, you decide to use mock endpoints for external API dependencies. Which approach should you take to simulate these external dependencies and validate your code's logic without invoking actual APIs?
- A
Use API Gateway's MOCK integration feature to simulate responses from external APIs.
- B
Use AWS X-Ray to record the external API calls and replay them during tests.
- C
Use a local Lambda function to deploy a temporary endpoint that mimics the external API.
- D
Use a testing library like AWS SDK Mock to stub the API responses during the test.
Show answer and explanation
Correct answer: A
Explanation
API Gateway's MOCK integration is a built-in feature that allows developers to simulate external API responses without requiring live endpoints. This is a highly efficient and cost-effective way to perform integration testing in a controlled environment, especially for serverless applications relying on external dependencies.
- A. Correct.
Correct: API Gateway's MOCK integration allows you to define static responses to simulate external API behavior, making it ideal for integration testing without invoking real APIs.
- B. Incorrect.
Incorrect: AWS X-Ray is used for distributed tracing and debugging, not for simulating or mocking external API calls.
- C. Incorrect.
Incorrect: Deploying a local Lambda function for this purpose is unnecessary and may add complexity to testing. A mock approach is more efficient.
- D. Incorrect.
Incorrect: While AWS SDK Mock can stub AWS service calls, it does not directly simulate external APIs managed through API Gateway.