aws-sam-translator1.94.0
Published
AWS SAM Translator is a library that transform SAM templates into AWS CloudFormation templates
pip install aws-sam-translator
Package Downloads
Authors
Project URLs
Requires Python
!=4.0,<=4.0,>=3.8
Dependencies
- boto3
==1.*,>=1.19.5
- jsonschema
<5,>=3.2
- typing-extensions
>=4.4
- pydantic
!=1.10.15,!=1.10.17,<3,>=1.8
- coverage
<8,>=5.3; extra == "dev"
- pytest-cov
<5,>=2.10; extra == "dev"
- pytest-xdist
<4,>=2.5; extra == "dev"
- pytest-env
<1,>=0.6; extra == "dev"
- pytest-rerunfailures
<12,>=9.1; extra == "dev"
- pyyaml
~=6.0; extra == "dev"
- ruff
~=0.4.5; extra == "dev"
- pytest
<8,>=6.2; extra == "dev"
- parameterized
~=0.7; extra == "dev"
- dateparser
~=1.1; extra == "dev"
- boto3
<2,>=1.23; extra == "dev"
- tenacity
~=8.0; extra == "dev"
- requests
~=2.28; extra == "dev"
- black
==24.3.0; extra == "dev"
- ruamel.yaml
==0.17.21; extra == "dev"
- mypy
~=1.3.0; extra == "dev"
- boto3-stubs
[appconfig,serverlessrepo]==1.*,>=1.19.5; extra == "dev"
- types-PyYAML
~=6.0; extra == "dev"
- types-jsonschema
~=3.2; extra == "dev"
AWS SAM transform
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
- The Complete AWS SAM Workshop
- AWS Serverless Developer Experience Workshop
- Deploying a "Hello, World!" application
- Testing in the cloud using the SAM CLI