A developer is building a serverless application with the AWS CDK that provisions multiple Lambda functions and API Gateway APIs during CloudFormation stack creation. On the developer workstation, both AWS SAM and AWS CDK are installed. How can the developer run a specific Lambda function locally for testing?
Choose an answer
Tap an option to check your answer.
Correct answer: Run cdk synth and then use sam local invoke with the function construct identifier and the path to the synthesized CloudFormation template..
Why this is the answer
The correct answer is to run cdk synth and then use sam local invoke. cdk synth generates a CloudFormation template from your CDK application. AWS SAM CLI, specifically sam local invoke, can then read this synthesized CloudFormation template to identify and execute a Lambda function locally, simulating the AWS Lambda environment. This allows for quick local testing without deploying to AWS. The other options are incorrect because: "Use sam package and sam deploy..." involves deploying to AWS, which is not local testing. "Run cdk synth and cdk deploy..." also involves deploying to AWS, not local testing. "Run cdk synth and then use sam local start-lambda..." starts a local endpoint for your Lambda functions, but sam local invoke is used for directly invoking a specific function with a test event, which is what the question asks for.
Pass your exam — without the endless answer hunt
Get every verified question and explanation for this exam in one place, and save hours of prep. 1,000+ certifications · 20+ languages · free to start.
Pass your exam faster → No card needed