AWS › AWS Serverless Application Model (SAM)

What is the SAM CLI, and how does it support local testing of serverless applications before deployment?

Beginner

Answer

The SAM CLI is a command line tool that lets you build, test, and debug serverless applications locally on your own machine using Docker to emulate the actual Lambda execution environment, allowing you to invoke functions and test API Gateway endpoints locally before ever deploying anything to AWS, significantly speeding up the development feedback loop compared to deploying to the cloud after every small code change.
sam local invoke MyFunction --event event.json
sam local start-api
Real-world example A developer building a new Lambda function uses sam local invoke to test their function's logic against a sample event directly on their laptop, catching several bugs before ever deploying the function to an actual AWS environment.

Common follow-ups: How accurately does the local Docker based emulation match the real Lambda execution environment?;What are the limitations of local testing compared to testing in an actual AWS environment?