AWS Certified Developer – Associate (DVA-C02) — Question 129
A developer is creating an AWS Lambda function. The Lambda function will consume messages from an Amazon Simple Queue Service (Amazon SQS) queue. The developer wants to integrate unit testing as part of the function's continuous integration and continuous delivery (CI/CD) process.
How can the developer unit test the function?
Answer options
- A. Create an AWS CloudFormation template that creates an SQS queue and deploys the Lambda function. Create a stack from the template during the CI/CD process. Invoke the deployed function. Verify the output.
- B. Create an SQS event for tests. Use a test that consumes messages from the SQS queue during the function's Cl/CD process.
- C. Create an SQS queue for tests. Use this SQS queue in the application's unit test. Run the unit tests during the CI/CD process.
- D. Use the aws lambda invoke command with a test event during the CIICD process.
Correct answer: D
Explanation
The correct answer is D because using the aws lambda invoke command allows for quick testing of the Lambda function by directly invoking it with a predefined test event. The other options involve setting up additional resources or processes that are unnecessary for simple unit testing, making them less efficient for integration into a CI/CD process.