项目作者: aws

项目描述 :
AWS Serverless Application Model (SAM) is an open-source framework for building serverless applications
高级语言: Python
项目地址: git://github.com/aws/serverless-application-model.git
创建时间: 2016-10-10T21:36:18Z
项目社区:https://github.com/aws/serverless-application-model

开源协议:Apache License 2.0

下载


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:

  1. Transform: AWS::Serverless-2016-10-31
  2. Resources:
  3. MyFunction:
  4. Type: AWS::Serverless::Function
  5. Properties:
  6. Runtime: nodejs18.x
  7. Handler: index.handler
  8. InlineCode: |
  9. exports.handler = async (event) => {
  10. console.log(event);
  11. }

And deploy it with the SAM CLI:

  1. 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:

  1. Resources:
  2. MyFunction:
  3. Type: AWS::Lambda::Function
  4. Properties:
  5. Code:
  6. ZipFile: |
  7. exports.handler = async (event) => {
  8. console.log(event);
  9. }
  10. Handler: index.handler
  11. Role: !GetAtt MyFunctionRole.Arn
  12. Runtime: nodejs18.x
  13. Tags:
  14. - Key: lambda:createdBy
  15. Value: SAM
  16. MyFunctionRole:
  17. Type: AWS::IAM::Role
  18. Properties:
  19. AssumeRolePolicyDocument:
  20. Version: "2012-10-17"
  21. Statement:
  22. - Action:
  23. - sts:AssumeRole
  24. Effect: Allow
  25. Principal:
  26. Service:
  27. - lambda.amazonaws.com
  28. ManagedPolicyArns:
  29. - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
  30. Tags:
  31. - Key: lambda:createdBy
  32. 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:

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

Set up dependencies:

  1. make init

Run tests:

  1. 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