简体   繁体   English

我是否可以在 SAM 模板中使用 AWS Cloud Formation 资源语法,反之亦然?

[英]Can I use the AWS Cloud Formation resource syntax into SAM template or vice-versa?

Recently, I have started learning AWS Cloud Formation (CF) and AWS Serverless Application Model (SAM).最近,我开始学习 AWS Cloud Formation (CF) 和 AWS Serverless Application Model (SAM)。 I found that there differences when it comes to syntax in its template files.我发现在其模板文件中的语法方面存在差异。 For instance, to create a Lambda resource in SAM, we would declare something like this:-例如,要在 SAM 中创建 Lambda 资源,我们将声明如下:-

Resources:
  HelloLambda:
    Type: AWS::Serverless::Function

Whereas in CF, we declare by this:-而在 CF 中,我们声明如下:-

Resources:
  HelloLambda:
    Type: AWS::Lambda::Function

Not just that there are few attributes/properties when it comes to Lambda that differs in SAM than a CF.不仅仅是在 SAM 中与 CF 不同的 Lambda 属性/属性很少。

I'm still not able to get my head around and confused.我仍然无法理解和困惑。 I have a few queries and would really appreciate if you can clear my doubts:-我有一些疑问,如果您能消除我的疑虑,我将不胜感激:-

  1. What was the need for SAM, if CF was already doing great things as IaC (Infrastructure as Code) for AWS Cloud?如果 CF 已经在为 AWS 云做 IaC(基础设施即代码)这样​​的伟大事情,那么对 SAM 的需求是什么?
  2. Why somebody would prefer to SAM instead of CF?为什么有人更喜欢 SAM 而不是 CF?
  3. Any finally, can I use the SAM resources (syntactical) to write in CF or vice-versa, for instance, can I declare a Lambda using the following syntax in a normal CF template or vice-versa:-最后,我可以使用 SAM 资源(语法)在 CF 中编写还是反之亦然,例如,我可以在普通 CF 模板中使用以下语法声明 Lambda,反之亦然:-

Resources: HelloLambda: Type: AWS::Serverless::Function资源:HelloLambda:类型:AWS::Serverless::Function

Cheers,干杯,

  1. What was the need for SAM, if CF was already doing great things as IaC (Infrastructure as Code) for AWS Cloud?如果 CF 已经在为 AWS 云做 IaC(基础设施即代码)这样​​的伟大事情,那么对 SAM 的需求是什么?

It simplifies developments which involve lambda and API gateway - a very popular combination.它简化了涉及lambda 和 API 网关的开发——一种非常流行的组合。 Doing the same things in pure CFN, would require extra steps (eg manual setup of integration methods), which many don't want, or don't need to, know how to make.在纯 CFN 中做同样的事情,需要额外的步骤(例如手动设置集成方法),许多人不希望或不需要知道如何制作。 Also SAM has custom command line tool , which helps you run and test your lambda+api gateway locally and provide number of test events not available through CFN, or hides complexities associated with deployments of your functions through CodeDeploy .此外,SAM 具有自定义命令行工具,可帮助您在本地运行和测试您的 lambda+api 网关,并提供通过 CFN 无法提供的测试事件数量,或通过CodeDeploy隐藏与您的功能部署相关的复杂性。 You can't do this easily with just CFN.仅使用 CFN 无法轻松做到这一点。

  1. Why somebody would prefer to SAM instead of CF?为什么有人更喜欢 SAM 而不是 CF?

Ability to easily test things locally combined with streamlined integration with CodeDeploy is very useful.能够在本地轻松测试事物以及与 CodeDeploy 的简化集成非常有用。 So its good for people who want to put more focus on writing code for their applications, rather then spending much time on setting up everything from scratch, which is more of DevOps job.因此,对于希望将更多精力放在为应用程序编写代码,而不是花费大量时间从头开始设置一切的人来说,这是很好的,这更多的是 DevOps 工作。

Any finally, can I use the SAM resources (syntactical) to write in CF or vice-versa, for instance, can I declare a Lambda using the following syntax in a normal CF template or vice-versa:-最后,我可以使用 SAM 资源(语法)在 CF 中编写还是反之亦然,例如,我可以在普通 CF 模板中使用以下语法声明 Lambda,反之亦然:-

SAM templates can contain CFN resources , but not the other way. SAM 模板可以包含 CFN 资源,但不能以其他方式包含。 The Resources section in SAM: SAM 中的资源部分:

  1. This section is similar to the Resources section of AWS CloudFormation templates.此部分类似于 AWS CloudFormation 模板的资源部分。 In AWS SAM templates, this section can contain AWS SAM resources in addition to AWS CloudFormation resources .在 AWS SAM 模板中,除了 AWS CloudFormation 资源之外,此部分还可以包含 AWS SAM资源

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM