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?
Select an option, then click Submit answer.
Reference / correct answer:
Use the aws lambda invoke command with a test event during the CIICD process.
Most accepted answer: D. Use the aws lambda invoke command with a test event during the CIICD process.
Community votes: C=5, D=10
Selected Answer: C Unit testing is a type of testing that verifies the correctness of individual units of source code, typically functions or methods. When unit testing a Lambda function that interacts with Amazon SQS, you can create a separate test SQS queue that the Lambda function interacts with during testing. You would then validate the behavior of the function based on its interactions with the test queue. This approach isolates the function's behavior from the rest of the system, which is a key principle of unit testing. Option A is incorrect because AWS CloudFormation is typically used for infrastructure deployment, not for unit testing. Option B is incorrect because it does not actually test the function; it only creates an event. Option D is incorrect because the 'aws lambda invoke' command is used to manually trigger a Lambda function, but doesn't necessarily facilitate testing the function's behavior when consuming messages from an SQS queue. upvoted 16 times
Selected Answer: D D is correct here. Both B and C are integration tests as they are using an actual SQS queue in the tests and not mocking it out. upvoted 13 times
Selected Answer: D Those who select C and still think they are right - Should study more about unit test & integrate testing before AWS upvoted 1 times
Selected Answer: D A) Eliminated - This approach involves creating and destroying AWS resources (SQS, Lambda) for each test, which increases the time, complexity, and potential costs associated with running tests. B) Eliminated - t involves real AWS resources (SQS) C) Eliminated - Even though it's meant for testing, you're still using an actual AWS service (SQS) to conduct the test, making it less of a unit test and more of an integration test. D) Correct - You use the aws lambda invoke command to invoke the Lambda function directly during the test process, without needing to rely on actual resources like an SQS queue. upvoted 1 times
Selected Answer: C Unit testing is a type of testing that verifies the correctness of individual units of source code, typically functions or methods upvoted 1 times