AWS SAM Translator is a library that transform SAM templates into AWS CloudFormation templates
Project description
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: nodejs16.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: nodejs16.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.7+ 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
Documentation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for aws-sam-translator-1.60.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba3c4e38c6dd2f7e530f71eec2012b491fb7cde934d0ff5db4145209995095dd |
|
MD5 | 6cdc55bee5dea3d8d1b9f7785a5866e3 |
|
BLAKE2b-256 | 58d042434a73d2908bed6b24ad7b6d17b45589621d35319938aeca9c6c83152d |
Hashes for aws_sam_translator-1.60.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b104e327a8542cb966ca9e1ddf7f94d7821497d4c8c4a66ef0eb5e2ec4212af1 |
|
MD5 | e5219c5a2910430e0bda5e98b14fb900 |
|
BLAKE2b-256 | c59529ab2ae58275464e18eb6342faf2b0c5a5cb2966b437f63ffcd1260acaeb |