The AWS Serverless Application Model (AWS SAM) transform is a AWS CloudFormation macro that transforms SAM templates into CloudFormation templates.
To use the SAM transform, add AWS::Serverless-2016-10-31 to the Transform section of your CloudFormation template.
Benefits of using the SAM transform include:
- Built-in best practices and sane defaults.
- Local testing and debugging with the AWS SAM CLI.
- Extension of the CloudFormation template syntax.
Save the following as template.yaml:
Transform: AWS::Serverless-2016-10-31Resources:
MyFunction:
Type: AWS::Serverless::FunctionProperties:
Runtime: nodejs18.xHandler: index.handlerInlineCode: | exports.handler = async (event) => { console.log(event); }And deploy it with the SAM CLI:
sam sync --stack-name sam-appThe AWS::Serverless::Function resource will create a AWS Lambda function that logs events it receives.
Under the hood, the template is transformed into the JSON equivalent of the following CloudFormation template:
Resources:
MyFunction:
Type: AWS::Lambda::FunctionProperties:
Code:
ZipFile: | exports.handler = async (event) => { console.log(event); }Handler: index.handlerRole: !GetAtt MyFunctionRole.ArnRuntime: nodejs18.xTags:
- Key: lambda:createdByValue: SAMMyFunctionRole:
Type: AWS::IAM::RoleProperties:
AssumeRolePolicyDocument:
Version: "2012-10-17"Statement:
- Action:
- sts:AssumeRoleEffect: AllowPrincipal:
Service:
- lambda.amazonaws.comManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRoleTags:
- Key: lambda:createdByValue: SAMFor a more thorough introduction, see the this tutorial in the Developer Guide.
You'll need to have Python 3.8+ installed.
Create a virtual environment:
python3 -m venv .venv
source .venv/bin/activateSet up dependencies:
make initRun tests:
make prSee DEVELOPMENT_GUIDE.md for further development instructions, and CONTRIBUTING.md for the contributing guidelines.
The best way to interact with the team is through GitHub. You can either create an issue or start a discussion.
You can also join the #samdev channel on Slack.