Question #756
A developer is troubleshooting integration issues between Amazon API Gateway and AWS Lambda in a REST API. They need to simulate the API Gateway environment locally to test endpoint integrations and debug issues without deploying changes to the production environment. Which AWS Serverless Application Model Command Line Interface (AWS SAM CLI) subcommand should they use?
Sam local invoke
Sam local generate-event
Sam local start-lambda
Sam local start-api
Explanation
The correct answer is D. Sam local start-api.
Why D is correct:
The sam local start-api command launches a local HTTP server that mimics Amazon API Gateway. It allows developers to test REST API endpoint integrations with Lambda functions locally by sending HTTP requests to the simulated API. This enables debugging of request/response flows, authorization, and payload transformations without deploying changes to AWS.
Why other options are incorrect:
- A. Sam local invoke: Invokes a single Lambda function directly but does not simulate API Gateway's HTTP endpoint integration.
- B. Sam local generate-event: Generates mock event payloads (e.g., API Gateway events) but does not simulate the API Gateway environment.
- C. Sam local start-lambda: Starts a local Lambda endpoint for programmatic invocations (e.g., from another service) but does not create an HTTP API simulation.
Key Points:
- Use sam local start-api to test end-to-end API Gateway + Lambda integrations locally.
- SAM CLI's local testing tools help debug serverless applications offline before deployment.
Answer
The correct answer is: D