exam questions

Exam AWS Certified Developer - Associate DVA-C02 All Questions

View all questions & answers for the AWS Certified Developer - Associate DVA-C02 exam

Exam AWS Certified Developer - Associate DVA-C02 topic 1 question 129 discussion

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?

  • 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.
Show Suggested Answer Hide Answer
Suggested Answer: D 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
gagol14
Highly Voted 1 year, 7 months ago
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
...
redfivedog
Highly Voted 1 year, 6 months ago
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
...
mooncake1
Most Recent 1 week, 4 days ago
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
...
sumanshu
1 month, 1 week ago
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
...
ShakthiGCP
1 month, 3 weeks ago
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
...
f271c23
1 month, 4 weeks ago
Selected Answer: C
option C seems more appropriate. As there is a clear isolation of test stage environment and it is staged prior to the deployment. Option D triggered manually and consuming from the same queue that was meant for the Production environment
upvoted 1 times
...
CloudChingon
2 months, 3 weeks ago
Selected Answer: D
It's testing so option D seems more logic. The other options would put a message in SQS.
upvoted 1 times
...
Anandesh
6 months, 2 weeks ago
Selected Answer: D
https://docs.aws.amazon.com/lambda/latest/dg/testing-guide.html
upvoted 1 times
...
65703c1
8 months, 2 weeks ago
Selected Answer: D
D is the correct answer.
upvoted 1 times
...
Moralles
10 months ago
Selected Answer: D
In the case of unit tests, whose objective is to isolate the tested unit, option D is the one that most isolates the unit.
upvoted 1 times
...
41eb566
10 months, 3 weeks ago
Selected Answer: C
To unit test the AWS Lambda function that consumes messages from an Amazon SQS queue as part of the CI/CD process, the developer can follow option C: 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.
upvoted 1 times
...
KillThemWithKindness
11 months, 3 weeks ago
Selected Answer: D
In production, our Lambda function code will directly access the AWS resources we defined in our function handler; however, in our unit tests we want to isolate our code and replace the AWS resources with simulations. This isolation facilitates running unit tests in an isolated environment to prevent accidental access to actual cloud resources. https://aws.amazon.com/blogs/devops/unit-testing-aws-lambda-with-python-and-mock-aws-services/
upvoted 1 times
...
SerialiDr
1 year ago
Selected Answer: D
D. Use the aws lambda invoke command with a test event during the CI/CD process: This option is closer to what unit testing entails. The aws lambda invoke command can be used to invoke the Lambda function with a simulated event payload that mimics an SQS message. This allows the developer to test the function's logic and handling of SQS messages without needing an actual SQS queue. The test can focus on how the function processes the input and generates output, which is the essence of unit testing.
upvoted 3 times
...
CrescentShared
1 year ago
Anybody find this question in the exam, please? The question itself looks so wrong to me, the action of testing the lambda function does not seem like a 'unit test' already... Isn't the unit test testing all the Classes inside the lambda function?
upvoted 2 times
...
Certified101
1 year, 1 month ago
Selected Answer: C
C there should be a seperate isolated test enviroment D will only invoke the lambda and not test SQS polling.
upvoted 2 times
...
tqiu654
1 year, 2 months ago
Selected Answer: D
ChatGPT:D
upvoted 1 times
...
ShawnWon
1 year, 2 months ago
B. Option A (CloudFormation template for SQS queue and Lambda function) involves more of an integration test rather than a unit test. It's typically preferable to keep unit tests isolated and focused on the specific functionality of the function. Option C (Create an SQS queue for tests) might involve additional setup and cleanup steps, and it could introduce dependencies that impact the isolation of unit tests. Option D (aws lambda invoke command with a test event) is similar to Option B, but creating a test event is generally more flexible and allows for a clearer representation of the expected input to the Lambda function.
upvoted 3 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago