AWS Certified Developer – Associate (DVA-C02) — Question 72
A developer is implementing an AWS Cloud Development Kit (AWS CDK) serverless application. The developer will provision several AWS Lambda functions and Amazon API Gateway APIs during AWS CloudFormation stack creation. The developer's workstation has the AWS Serverless Application Model (AWS SAM) and the AWS CDK installed locally.
How can the developer test a specific Lambda function locally?
Answer 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.
Correct answer: C
Explanation
The correct answer is C because it utilizes the 'sam local invoke' command to test the Lambda function directly, which allows for local testing with specified events. Options A and B involve deploying to the cloud, which does not facilitate local testing. Option D uses 'sam local start-lambda', which is for starting a local Lambda service but does not directly invoke a function for testing.