- We write code to create infrastructure
- Declarative in Nature -- What you see is what you have --> Template --> By reading these are the resources availabe in AWS --> Code review
-- We can take this templates and store them in Git or S3 or any other -- Trace back the versions
- CLI -- As a Devops engineer use CLI when you want to execute short or quick actions (Like listing s3 buckets, ec2 instance listing them)
- When you want to use simple script to get resouces which are using in AWS then use CLI
- CFT is for creating actual resources like 10 ec2 instances, s3 and etc
- It supports both JSON AND YAML
- Crating Infra (Primary)
- Drift Detection : Ex: We have created EC2 + S3 using CFT, Like someone went to the UI and they modified the changed something like s3 versioned enabled or disabled something like that
- In CFT we have option called Detect Drift --> Periodically check and changes
NOTE : For example we have a YAML in local machine, Now how do you submit to AWS CFT (created using CLI OR WEB UI) , IN CFT we have STACKS --> Create Stacks --> import YAML which is in local
CFT DOCS : https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html, https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-guide.html, https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-anatomy.html, https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket-versioningconfig.html
AWSTemplateFormatVersion: "2010-09-09" -- VERSION
Description: A sample template -- DESCRIPTION OF THE TEMPLATE SPECIFIC
Resources: -- WE CAN CREATED ANY NO.OF RESROUCES
MyEC2Instance: #An inline comment ---NAME CAN BE ANYTHING
Type: "AWS::EC2::Instance" -- LIKE S3, EC2 AND ETC
Properties:
ImageId: "ami-0ff8a91507f77f867" #Another comment -- This is a Linux AMI -- we parameterize the imageid if the same template is used by different teams
InstanceType: t2.micro
KeyName: testkey
BlockDeviceMappings:
-
DeviceName: /dev/sdm
Ebs:
VolumeType: io1
Iops: 200
DeleteOnTermination: false
VolumeSize: 20
DOCS FOR EC2 : https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-instance.html
CREATE CFT
- AWS console --> Serach for CloudFormation --> Create Stack (USED TO CREATE TEMPLATES) --> iT WILL CONVERT TO API CALL AND SENDS
- Select create template in designer and create template in designer

- drag and drop the resources that are needed and add the properteries or metadata and etc to it.
- opiton 2 :

- give name --> next --> next --> submit (no need to change anything)

- AWS will store all the templates that we have in S3 bydefault
- DRIFT DETECTION : IF SOMEONE MANUALLY CHANGED IN THE WEB UI WE CAN CHECK THE CHANGES

- After clicking on drift detet wait for 1 or 2 minutes to detec
- Click on view drift results

- Now you can see the exact action what is done
- Check for bucket logging to find who did it
- Install YAML, AWS ToolKit extensions in VS-CODE




