如何将无服务器应用程序模型 (SAM) 模板转换为 Cloudformation?

Vic*_*tor 5 amazon-web-services aws-cloudformation aws-sam-cli aws-sam serverless-application-model

这个答案我了解到 SAM 是 Cloudformation 的一种转换。

有没有办法通过控制台、CLI 或其他方式从 SAM 模板获取转换后的 Cloudformation 模板?

小智 8

我猜您想将打包的 SAM 模板转换为普通的 Cloudformation 模板。

您可以通过以下简单步骤实现此目的:

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
Run Code Online (Sandbox Code Playgroud)

现在,您在 output_file.json 处有了一个打包的普通 CloudFormation 模板

有关更多信息,请访问https://github.com/awslabs/serverless-application-model/blob/develop/bin/sam-translate.py


jar*_*mod 5

对于已部署的 SAM 项目,您应该在 CloudFormation 控制台中找到原生 CloudFormation 模板、转换后模板。选择您的堆栈,然后打开Template选项卡。您还可以通过 awscli 使用aws cloudformation get-template.

您还可以使用 SAM cli,例如:

sam package \
  --output-template-file output.yaml \
  --s3-bucket mybucketname
Run Code Online (Sandbox Code Playgroud)