AWS Certified Developer Associate DVA-C02 Practice Question
A developer is building a new AWS Lambda function using Python. The function is triggered by Amazon S3 object-creation events and contains complex business logic that needs to be validated. The developer needs to write repeatable tests that verify only the function's core logic without making actual calls to other AWS services. What is the MOST effective approach for unit testing this function's logic?
Write an AWS CLI script to invoke the deployed Lambda function, passing a base64-encoded S3 event as the payload.
Use the AWS SAM CLI command sam local invoke with a sample S3 event JSON file to run the function in a local Docker container.
Mock the S3 event and AWS SDK clients, and then invoke the Lambda handler function directly with the mock event.
Deploy the function to a development environment and upload a test object to the S3 bucket to trigger an invocation.
The most effective approach for unit testing the Lambda function's core logic is to mock the S3 event and any AWS SDK clients it uses. This allows the developer to invoke the handler function directly with a simulated event and control the behavior of external dependencies, ensuring the test is isolated and focuses exclusively on the business logic. This method is fast, repeatable, and does not require an active AWS environment or incur costs from service calls. Deploying the function to test, or using sam local invoke, are forms of integration testing, as they involve more components than just the isolated unit of code.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is the difference between a unit test and an integration test?
Open an interactive chat with Bash
Why is isolation important for unit tests?
Open an interactive chat with Bash
What tools are commonly used to mock dependencies in unit testing?
Open an interactive chat with Bash
AWS Certified Developer Associate DVA-C02
Development with AWS Services
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
Pass with Confidence.
IT & Cybersecurity Package
You have hit the limits of our free tier, become a Premium Member today for unlimited access.
Military, Healthcare worker, Gov. employee or Teacher? See if you qualify for a Community Discount.
Monthly
$19.99
$19.99/mo
Billed monthly, Cancel any time.
3 Month Pass
$44.99
$14.99/mo
One time purchase of $44.99, Does not auto-renew.
MOST POPULAR
Annual Pass
$119.99
$9.99/mo
One time purchase of $119.99, Does not auto-renew.
BEST DEAL
Lifetime Pass
$189.99
One time purchase, Good for life.
What You Get
All IT & Cybersecurity Package plans include the following perks and exams .