What is the Serverless Application Model?
SAM is a toolkit designed to enhance the developer experience when building and running serverless applications on AWS. Similar to an architect creating a detailed blueprint for a house, SAM provides a comprehensive plan for your serverless infrastructure. This approach means you don’t need to focus on every individual resource—instead, you work from a well-defined template that outlines how everything fits together.
The Role of SAM in Application Development
As a developer or architect, you define a SAM template—typically written in YAML (or JSON)—which specifies all the serverless resources required for your application. This includes:- AWS Lambda functions
- API Gateways
- Databases
- And other essential services
The SAM CLI workflow begins with a configuration file similar to an AWS CloudFormation template. Once your template is defined, it is packaged along with your application code and uploaded to an S3 bucket. AWS CloudFormation then utilizes this template to swiftly deploy the defined resources.
Key SAM CLI Commands
The SAM CLI offers a suite of commands to enhance the serverless development cycle. Below is an example workflow:- sam logs: Retrieve logs for your Lambda function.
- sam validate: Check your SAM template for errors.
- sam publish: Share your application via the AWS Serverless Application Repository.
SAM and AWS CloudFormation
SAM is an extension of AWS CloudFormation and follows a similar template-based deployment process. When you create a SAM template, you describe the entirety of your serverless application, including functions, APIs, and other resources. Once packaged and uploaded to an S3 bucket, AWS CloudFormation deploys the resources as defined in your template. This integration not only sets up your infrastructure but also generates a change set for managing updates efficiently.
Leveraging SAM and its CLI can significantly streamline the creation and management of complex serverless architectures, resulting in an organized and efficient deployment process.