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: C 🗳️

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, 5 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, 4 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 10 times
...
ShakthiGCP
Most Recent 1 day, 22 hours 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
4 days, 9 hours 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
1 month 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
4 months, 3 weeks ago
Selected Answer: D
https://docs.aws.amazon.com/lambda/latest/dg/testing-guide.html
upvoted 1 times
...
65703c1
6 months, 3 weeks ago
Selected Answer: D
D is the correct answer.
upvoted 1 times
...
Moralles
8 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
9 months 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
9 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
11 months 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
11 months 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 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 ago
Selected Answer: D
ChatGPT:D
upvoted 1 times
...
ShawnWon
1 year 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 2 times
...
dilleman
1 year, 2 months ago
Selected Answer: D
Option D is the only true unit test.
upvoted 3 times
...
love777
1 year, 3 months ago
Selected Answer: B
Explanation: Option B involves simulating the SQS event trigger for testing purposes. This is a common practice in AWS Lambda unit testing. Here's how it works: SQS Event for Tests: In your unit test code, you can create an SQS event object that simulates the event structure that Lambda receives when an SQS message is consumed. This event object will contain the necessary information, such as the message content, message attributes, etc. Testing Logic: You can then pass this event object to your Lambda function's handler function as if it were an actual SQS event. This allows you to test your Lambda function's logic as it would work in response to an SQS message. Mocking Dependencies: During unit testing, you might want to mock any AWS service calls, such as SQS, to isolate your Lambda function's logic from external services.
upvoted 7 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