AWS SAM
The AWS Serverless Application Model (SAM) is a framework for building serverless applications. AWS SAM is split into two parts, a shorthand syntax that adds additional resources on top of CloudFormation and a command line interface (CLI).
AWS SAM Template
Globals
The global sections of the SAM template allows default properties to be set across all Lambda functions. You can also override each of these properties at a specific function level.
Native AOT support
AWS SAM also provides support for compiling .NET 7 applications with native AOT. To do that, add an additional metadata property to the Lambda function definition and ensure the Runtime
is set to provided.al2
. Adding this additional metadata property tells SAM to use the Amazon.Lambda.Tools
global CLI. For more information on native AOT, check out this walkthrough.
Function
Lambda functions are specified using a resource of type AWS::Serverless::Function
. There are 8 supported resources that can be found in the AWS Docs. The CodeUri
property tells the SAM CLI which folder the code for this function is stored under.
IAM permissions
SAM provides a set of pre-built policy templates to simplify IAM policies.
Globals
The global sections of the SAM template allows default properties to be set across all Lambda functions. You can also override each of these properties at a specific function level.
Native AOT support
AWS SAM also provides support for compiling .NET 7 applications with native AOT. To do that, add an additional metadata property to the Lambda function definition and ensure the Runtime
is set to provided.al2
. Adding this additional metadata property tells SAM to use the Amazon.Lambda.Tools
global CLI. For more information on native AOT, check out this walkthrough.
Function
Lambda functions are specified using a resource of type AWS::Serverless::Function
. There are 8 supported resources that can be found in the AWS Docs. The CodeUri
property tells the SAM CLI which folder the code for this function is stored under.
IAM permissions
SAM provides a set of pre-built policy templates to simplify IAM policies.
SAM CLI
The SAM CLI is used to build
and deploy
your serverless application.
The sam build
command both compiles the application code and applies generates a CloudFormation ready template. Under the hood, the build command runs a foreach over all of the specified AWS::Serverless::Function
resources, and compiles your .NET code. The compiled code is then output to the .aws-sam
folder.
After running sam build
, run sma deploy --guided
to deploy the application to AWS.
If video is more your thing, there is an entire playlist on my YouTube channel going from AWS SAM basics through to complex CICD.