DVA-C02 Question 251
Single answerYou are developing a serverless application using AWS Lambda and API Gateway. To validate the integration between your Lambda function and external APIs during testing, you decide to use mock endpoints. Which of the following approaches would best suit this scenario?
- A
Configure an API Gateway stage with mock integration responses.
- B
Use AWS X-Ray to simulate API responses for testing.
- C
Write a Lambda function that mocks the external API and deploy it as a separate endpoint.
- D
Set up an Amazon S3 bucket to serve as a mock endpoint for the external API.
Show answer and explanation
Correct answer: A
Explanation
When testing integrations between AWS Lambda and external APIs, API Gateway's built-in mock integration feature is the most efficient solution. It allows you to define and test predictable responses without relying on the actual external API. This ensures your integration tests are consistent and independent of external factors like downtime or rate limits.
- A. Correct.
Correct: API Gateway stages with mock integration responses allow you to simulate responses without invoking the actual backend. This is an efficient way to test integration without external dependencies.
- B. Incorrect.
Incorrect: AWS X-Ray is primarily used for tracing and debugging application performance, not for simulating or mocking API responses.
- C. Incorrect.
Incorrect: Writing and deploying a separate Lambda function to mock the API is unnecessary overhead when API Gateway already provides a built-in mechanism for mocking responses.
- D. Incorrect.
Incorrect: S3 is designed for object storage and not as a suitable mechanism to simulate API responses, especially for integration testing scenarios.