2
votes

Recently, I have started learning AWS Cloud Formation (CF) and 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:-

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

Whereas in CF, we declare by this:-

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.

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?
  2. Why somebody would prefer to SAM instead of 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:-

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

Cheers,

1

1 Answers

1
votes
  1. What was the need for SAM, if CF was already doing great things as IaC (Infrastructure as Code) for AWS Cloud?

It simplifies developments which involve lambda and API gateway - a very popular combination. Doing the same things in pure CFN, would require extra steps (e.g. manual setup of integration methods), which many don't want, or don't need to, know how to make. 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. You can't do this easily with just CFN.

  1. Why somebody would prefer to SAM instead of CF?

Ability to easily test things locally combined with streamlined integration with CodeDeploy is very useful. 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.

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 templates can contain CFN resources, but not the other way. The Resources section in SAM:

  1. This section is similar to the Resources section of AWS CloudFormation templates. In AWS SAM templates, this section can contain AWS SAM resources in addition to AWS CloudFormation resources.