"Serverless means no infrastructure code." It still needs some. A single Lambda function needs an execution role, permissions, a log group, often an API Gateway endpoint and a table. Written in raw CloudFormation, that is pages of YAML. AWS SAM, the Serverless Application Model, is an open-source framework that makes it a few lines.
The template: shorthand for CloudFormation
A SAM template is a CloudFormation template with one extra line at the top:
Transform: AWS::Serverless-2016-10-31
That line lets you use short resource types such as AWS::Serverless::Function, AWS::Serverless::Api and AWS::Serverless::SimpleTable. During deployment, SAM expands them into the full set of CloudFormation resources: the function, its role, its permissions, the API stage and so on. Because the result is plain CloudFormation, you can mix SAM resources with any normal CloudFormation resource in the same template.
Connectors go one step further: you state "this function writes to this table", and SAM generates the IAM permissions for that intent.
The SAM CLI
The command line covers the whole loop:
sam initcreates a project from a template: code, atemplate.yamland config.sam buildinstalls dependencies and packages the code.sam local invokeandsam local start-apirun functions and APIs on your machine in a container (Docker or a compatible runtime is required).sam deploy --guideddeploys through CloudFormation and saves your answers for next time.sam syncpushes code changes to a development stack quickly while you work.
A common mistake is testing only locally. The local container does not reproduce IAM permissions or service quotas, so also test in a real development account.
Safe releases built in
Add AutoPublishAlias and a DeploymentPreference to a function, and SAM creates the CodeDeploy setup for you: types such as Canary10Percent10Minutes or Linear10PercentEvery1Minute, pre- and post-traffic test functions, and CloudWatch alarms that trigger an automatic rollback. The first deployment must create a version to shift from, so turn this on from the second release.
Where AI fits
SAM is a quick way to scaffold a Lambda plus Amazon Bedrock app: sam init gives you a function and an API, you add a policy statement that allows the Bedrock invoke actions on the model you use, and sam deploy gives you a working AI endpoint you can version and canary like any other release. AI coding assistants can do the scaffolding too: the open-source AWS Serverless MCP Server from AWS Labs gives assistants tools such as sam_init, sam_build, sam_deploy and sam_local_invoke. It runs read-only by default; deploying requires turning on write access explicitly, which is the right default when an assistant acts in your account.
Quick recap
- SAM is CloudFormation shorthand for serverless: one Transform line, short resource types.
- Build, test locally, deploy with the SAM CLI.
- Canary releases built in through DeploymentPreference and CodeDeploy.