简体   繁体   English

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

[英]How to transform a Serverless Application Model (SAM) template to Cloudformation?

From this answer I understand that SAM is a transform of Cloudformation.这个答案中,我了解到 SAM 是 Cloudformation 的一种转换。

Is there a way to get the transformed Cloudformation template from a SAM template via the console, CLI, or another way?有没有办法通过控制台、CLI 或其他方式从 SAM 模板中获取转换后的 Cloudformation 模板?

For SAM projects already deployed, you should find the native CloudFormation template, post transformation, in the CloudFormation console.对于已部署的 SAM 项目,您应该在 CloudFormation 控制台中找到原生 CloudFormation 模板(转换后)。 Select your stack, then open the Template tab. Select 您的堆栈,然后打开Template选项卡。 You can also retrieve this via the awscli using aws cloudformation get-template .您还可以使用aws cloudformation get-template通过 awscli 检索它。

You can also use the SAM cli, for example:您还可以使用 SAM cli,例如:

sam package \
  --output-template-file output.yaml \
  --s3-bucket mybucketname

I'm guessing you want to convert packaged SAM Template to a vanilla Cloudformation template.我猜您想将打包的 SAM 模板转换为普通的 Cloudformation 模板。

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现在您在 output_file.json 处有一个打包的 vanilla CloudFormation 模板

More on this at https://github.com/awslabs/serverless-application-model/blob/develop/bin/sam-translate.py更多信息请访问https://github.com/awslabs/serverless-application-model/blob/develop/bin/sam-translate.py

There is a feature request for this.对此有一个功能请求 Devs mentions a work-around using sam validate --debug .开发人员提到了使用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. Akshay 和 Jarmod 的解决方案似乎需要已经部署您的代码或完整的应用程序,而这种方法完全在本地工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Cloudformation模板到SAM还是无服务器? - Cloudformation template to SAM or serverless? Amazon 无服务器应用程序模型 (SAM) 条件包含在模板中 - Amazon Serverless Application Model (SAM) conditional includes in a template 如何在lambda函数的SAM(无服务器应用程序模型)模板中为多个表定义CRUD策略? - How to define CRUD policy in SAM (Serverless application model) template to more than one table for a lambda functio? AWS 无服务器应用程序模型 (SAM) — 如何更改 StageName? - AWS Serverless Application Model (SAM) -- How do I change StageName? 如何从 SAm 项目创建 cloudformation 模板? - How to create cloudformation template from SAm project? 带有Cloudformation SAM的AWS :: Serverless :: Api资源策略 - AWS::Serverless::Api Resource Policy with Cloudformation SAM 如何在AWS SAM模板中为AWS :: Serverless :: Api添加请求验证器? - How to add a request validator in a AWS SAM template for AWS::Serverless::Api? AWS SAM(无服务器应用程序模型)和无服务器框架有什么区别? - What's the difference between AWS SAM (Serverless Application Model) and serverless framework? SAM模板和Cloudformation模板的区别 - Difference between SAM template and Cloudformation template 如何在 CloudFormation 模板中将 AWS::ApiGateway::Resource 添加到 AWS::Serverless::Api - How to add an AWS::ApiGateway::Resource to an AWS::Serverless::Api in CloudFormation template
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM