Jeff’s Note #
Unlike generic exam dumps, ADH analyzes this scenario through the lens of a Real-World Lead Developer.
For AWS DVA-C02 candidates, the confusion often lies in understanding how to correctly leverage AWS CDK synthesized templates together with SAM CLI commands for local testing.
In production, this is about knowing exactly how local invocation works and which tools properly interpret CDK’s CloudFormation artifacts. Let’s drill down.
The Certification Drill (Simulated Question) #
Scenario #
A fintech startup, Neobank Solutions, is building a highly scalable serverless payment platform using AWS CDK. The Lead Developer needs to provision several AWS Lambda functions and Amazon API Gateway APIs via AWS CloudFormation stacks created by CDK. On their development workstation, both AWS CDK and AWS Serverless Application Model (AWS SAM) CLI tools are installed. They want to test a specific Lambda function locally before deploying to AWS.
The Requirement: #
Determine the best local testing approach that enables invocation of the Lambda function using the existing CDK setup and SAM tools.
The Options #
- A) Run the
sam packageandsam deploycommands. Create a Lambda test event from the AWS Management Console. Test the Lambda function. - B) Run the
cdk synthandcdk deploycommands. Create a Lambda test event from the AWS Management Console. Test the Lambda function. - C) Run the
cdk synthandsam local invokecommands with the function construct identifier and the path to the synthesized CloudFormation template. - D) Run the
cdk synthandsam local start-lambdacommands with the function construct identifier and the path to the synthesized CloudFormation template.
Google adsense #
leave a comment:
Correct Answer #
D
Quick Insight: The Developer Imperative #
Running
cdk synthgenerates the CloudFormation template which defines your Lambda, but SAM CLI’s local invoke tooling relies on this template file to spin up a local Lambda runtime.The
sam local start-lambdacommand effectively creates a local Lambda endpoint you can invoke with the function identifier. This is the correct combination to test a Lambda defined by CDK templates locally.Simply deploying or testing from the console (options A and B) do not satisfy the requirement for local invocation on the developer workstation.
Content Locked: The Expert Analysis #
You’ve identified the answer. But do you know the implementation details that separate a Junior from a Senior?
The Expert’s Analysis #
Correct Answer #
Option D
The Winning Logic #
Local testing Lambda functions defined in AWS CDK requires two steps. First, run cdk synth to generate the CloudFormation template which contains the Lambda function resources and their configurations. Then, SAM CLI commands use this synthesized template to spin up a local Lambda runtime environment.
sam local start-lambdaboots a local endpoint that emulates AWS Lambda service, enabling invocation via SDK or CLI calls.- Using the function construct identifier (logical ID from the CloudFormation template) allows SAM CLI to identify the specific Lambda to run.
- This local endpoint works well for iterative development, debugging, and lambda event testing without deploying to AWS.
The Trap (Distractor Analysis): #
- Why not A? The SAM commands
sam packageandsam deployare only relevant if you’re using SAM templates from scratch. They don’t support CDK workflows directly, and testing only from the AWS console fails the “local test” criterion. - Why not B? While
cdk deploydeploys resources, it doesn’t provide local testing tooling. Console testing again is not local. - Why not C?
sam local invokeinvokes Lambda locally but requires a packaged artifact or direct code path; it doesn’t work simply by passing a synthesized CloudFormation template without packaging.
The Technical Blueprint #
Relevant CLI Commands to Run #
# 1. Synthesize CloudFormation from CDK app
cdk synth > template.yaml
# 2. Start local Lambda service emulation with SAM CLI
sam local start-lambda --template template.yaml
# 3. In another terminal, invoke the lambda function by logical ID
aws lambda invoke --function-name YourFunctionLogicalID --endpoint-url http://localhost:3001 response.json
The Comparative Analysis #
| Option | API Complexity | Performance | Use Case |
|---|---|---|---|
| A | Low (pure SAM packing) | N/A (cloud deploy) | Deploy & test only in AWS |
| B | Low (CDK deploy) | N/A (cloud deploy) | Deploy & test only in AWS |
| C | Medium (partial local invoke) | Unsupported usage | Incorrectly expects SAM to run local invoke with CF template only |
| D | Medium (SAM start-lambda + CDK template) | Fast (local lambda invocation) | Local iterative testing with CDK-generated template |
Real-World Application (Practitioner Insight) #
Exam Rule #
For the exam, always pick sam local start-lambda when you see local Lambda testing with AWS CDK synthesized artifacts.
Real World #
In reality, developers often combine AWS SAM CLI with AWS CDK by synthesizing templates and then invoking Lambda locally. Although CDK can deploy directly, integrating SAM CLI enables faster local iteration and debugging before pushing changes to the cloud.
(CTA) Stop Guessing, Start Mastering #
Disclaimer
This is a study note based on simulated scenarios for the AWS DVA-C02 exam.