Skip to content

The AWS Serverless Application Model (AWS SAM) transform is a AWS CloudFormation macro that transforms SAM templates into CloudFormation templates.

License

Notifications You must be signed in to change notification settings

aws/serverless-application-model

Folders and files

NameName
Last commit message
Last commit date
Mar 1, 2025
Sep 11, 2024
Nov 6, 2024
Jan 11, 2022
Feb 28, 2025
Jun 25, 2024
Apr 18, 2025
Apr 10, 2025
Apr 18, 2025
Apr 3, 2025
Feb 17, 2023
Dec 14, 2018
Jan 18, 2023
Oct 31, 2022
Oct 23, 2020
Jan 22, 2025
Mar 22, 2018
Nov 25, 2022
May 25, 2018
Aug 12, 2024
Nov 6, 2023
Jul 14, 2022
Feb 9, 2023
Feb 23, 2023
May 30, 2024
Apr 4, 2018
Nov 6, 2023
Jan 3, 2022
Apr 5, 2017
Sep 1, 2022
Nov 6, 2023
Oct 31, 2024
May 30, 2024
Mar 9, 2022
Nov 6, 2023

AWS SAM transform

Tests Update schema PyPI PyPI - Python Version Contribute with Gitpod

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.

Getting started

Save the following as template.yaml:

Transform: AWS::Serverless-2016-10-31
Resources:
  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
      Runtime: nodejs18.x
      Handler: index.handler
      InlineCode: |
        exports.handler = async (event) => {
          console.log(event);
        }

And deploy it with the SAM CLI:

sam sync --stack-name sam-app

The 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::Function
    Properties:
      Code:
        ZipFile: |
          exports.handler = async (event) => {
            console.log(event);
          }
      Handler: index.handler
      Role: !GetAtt MyFunctionRole.Arn
      Runtime: nodejs18.x
      Tags:
        - Key: lambda:createdBy
          Value: SAM
  MyFunctionRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Action:
              - sts:AssumeRole
            Effect: Allow
            Principal:
              Service:
                - lambda.amazonaws.com
      ManagedPolicyArns:
        - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
      Tags:
        - Key: lambda:createdBy
          Value: SAM

For a more thorough introduction, see the this tutorial in the Developer Guide.

Contributing

Setting up development environment

You'll need to have Python 3.8+ installed.

Create a virtual environment:

python3 -m venv .venv
source .venv/bin/activate

Set up dependencies:

make init

Run tests:

make pr

See DEVELOPMENT_GUIDE.md for further development instructions, and CONTRIBUTING.md for the contributing guidelines.

Getting help

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.

Learn more

Workshops and tutorials

Documentation