#CloudFormation

AWS-native Infrastructure as Code.


#Basic Template

yaml
1# template.yaml
2AWSTemplateFormatVersion: '2010-09-09'
3Description: Simple EC2 instance
4
5Parameters:
6  InstanceType:
7    Type: String
8    Default: t2.micro
9
10Resources:
11  WebServer:
12    Type: AWS::EC2::Instance
13    Properties:
14      ImageId: ami-0c55b159cbfafe1f0
15      InstanceType: !Ref InstanceType
16      Tags:
17        - Key: Name
18          Value: WebServer
19
20Outputs:
21  PublicIP:
22    Value: !GetAtt WebServer.PublicIp

#Deploy

bash
1aws cloudformation create-stack \
2  --stack-name my-stack \
3  --template-body file://template.yaml
4
5aws cloudformation update-stack \
6  --stack-name my-stack \
7  --template-body file://template.yaml
8
9aws cloudformation delete-stack \
10  --stack-name my-stack

#When to Use

Use CloudFormationUse Terraform
AWS-onlyMulti-cloud
Deep AWS integrationTeam expertise
SAM for serverlessExisting state