Skip to main content

AWS DVA-C02 Drill: Local Lambda Testing - AWS CDK & SAM Integration Nuances

Jeff Taakey
Author
Jeff Taakey
21+ Year Enterprise Architect | AWS SAA/SAP & Multi-Cloud Expert.

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 package and sam deploy commands. Create a Lambda test event from the AWS Management Console. Test the Lambda function.
  • B) Run the cdk synth and cdk deploy commands. Create a Lambda test event from the AWS Management Console. Test the Lambda function.
  • C) Run the cdk synth and sam local invoke commands with the function construct identifier and the path to the synthesized CloudFormation template.
  • D) Run the cdk synth and sam local start-lambda commands 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 synth generates 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-lambda command 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-lambda boots 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 package and sam deploy are 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 deploy deploys resources, it doesn’t provide local testing tooling. Console testing again is not local.
  • Why not C? sam local invoke invokes 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.

The DevPro Network: Mission and Founder

A 21-Year Tech Leadership Journey

Jeff Taakey has driven complex systems for over two decades, serving in pivotal roles as an Architect, Technical Director, and startup Co-founder/CTO.

He holds both an MBA degree and a Computer Science Master's degree from an English-speaking university in Hong Kong. His expertise is further backed by multiple international certifications including TOGAF, PMP, ITIL, and AWS SAA.

His experience spans diverse sectors and includes leading large, multidisciplinary teams (up to 86 people). He has also served as a Development Team Lead while cooperating with global teams spanning North America, Europe, and Asia-Pacific. He has spearheaded the design of an industry cloud platform. This work was often conducted within global Fortune 500 environments like IBM, Citi and Panasonic.

Following a recent Master’s degree from an English-speaking university in Hong Kong, he launched this platform to share advanced, practical technical knowledge with the global developer community.


About This Site: AWS.CertDevPro.com


AWS.CertDevPro.com focuses exclusively on mastering the Amazon Web Services ecosystem. We transform raw practice questions into strategic Decision Matrices. Led by Jeff Taakey (MBA & 21-year veteran of IBM/Citi), we provide the exclusive SAA and SAP Master Packs designed to move your cloud expertise from certification-ready to project-ready.