DVA-C02 Question 249
Single answerYou are developing a serverless application using AWS Lambda and API Gateway. To perform integration testing, you need to validate the interaction between your Lambda function and an external HTTP API. However, the external API is not yet available, so you decide to use mock endpoints for the testing. Which approach should you use to achieve this?
- A
Use AWS API Gateway's Mock Integration feature to create a mock response for the external API.
- B
Deploy the Lambda function with a hard-coded mock response to simulate the external API.
- C
Use AWS CloudFormation to provision a temporary mock server for the external API.
- D
Use AWS X-Ray to mock the external API's responses during integration testing.
Show answer and explanation
Correct answer: A
Explanation
The AWS API Gateway Mock Integration feature is designed specifically for creating mock responses, which makes it an ideal choice for simulating external API interactions during integration testing. This approach ensures that your Lambda function can be tested without requiring the actual external API to be available, and it doesn’t involve modifying the function's code or provisioning unnecessary infrastructure.
- A. Correct.
Correct. AWS API Gateway's Mock Integration feature allows you to define mock responses for an endpoint, making it suitable for simulating the external API's behavior during integration testing.
- B. Incorrect.
Incorrect. Hard-coding a mock response in the Lambda function is not recommended because it requires modifying the function's code, making it less reusable and harder to maintain.
- C. Incorrect.
Incorrect. AWS CloudFormation is an infrastructure-as-code tool and doesn’t provide native features to create temporary mock servers. It’s not suitable for this use case.
- D. Incorrect.
Incorrect. AWS X-Ray is used for tracing and debugging distributed applications but does not have the capability to mock API responses.