How to transform a Serverless Application Model (SAM) template to Cloudformation?
G

3

14

From this answer I understand that SAM is a transform of Cloudformation.

Is there a way to get the transformed Cloudformation template from a SAM template via the console, CLI, or another way?

Glazing answered 6/4, 2020 at 1:50 Comment(0)
N
10

For SAM projects already deployed, you should find the native CloudFormation template, post transformation, in the CloudFormation console. Select your stack, then open the Template tab. You can also retrieve this via the awscli using aws cloudformation get-template.

You can also use the SAM cli, for example:

sam package \
  --output-template-file output.yaml \
  --s3-bucket mybucketname
Napiform answered 6/4, 2020 at 2:14 Comment(1)
super useful, thanks a lot!Lautrec
I
8

I'm guessing you want to convert packaged SAM Template to a vanilla Cloudformation template.

You can achieve this with the following easy steps:

pip install aws-sam-translator docopt

wget https://raw.githubusercontent.com/awslabs/serverless-application- model/develop/bin/sam-translate.py`

python sam-translate.py --template-file=input_file.yml --output-template=output_file.json

Now you have a packaged vanilla CloudFormation template at output_file.json

More on this at https://github.com/awslabs/serverless-application-model/blob/develop/bin/sam-translate.py

Intarsia answered 8/4, 2020 at 5:38 Comment(1)
Wrote a Nix flake for the translator app. Run like this: nix run github:alexoundos/aws-sam-translator-app -- --help.Gumshoe
U
4

There is a feature request for this. Devs mentions a work-around using sam validate --debug. It will show the transformed template, but also some other debugging info.

The solutions by Akshay and Jarmod seem to require having already deployed your code or full application, while this method works completely local.

Unerring answered 24/7, 2022 at 13:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.