AWS CloudFormation is a service that helps you model and set up your Amazon Web Services resources so that you can spend less time managing those resources and more time focusing on your applications that run in AWS
You create a template that describes all the AWS resources that you want (like Amazon EC2 instances or Amazon RDS DB instances), and AWS CloudFormation takes care of provisioning and configuring those resources for you. You don't need to individually create and configure AWS resources and figure out what's dependent on what; AWS CloudFormation handles all of that.
For a scalable web application that also includes a back-end database, you might use an Auto Scaling group, an Elastic Load Balancing load balancer, and an Amazon Relational Database Service database instance. Normally, you might use each individual service to provision these resources. And after you create the resources, you would have to configure them to work together. All these tasks can add complexity and time before you even get your application up and running.
By using AWS CloudFormation, you easily manage a collection of resources as a single unit.
>Quickly Replicate Your Infrastructure
>Easily Control and Track Changes to Your Infrastructure
AWS CloudFormation Best Practices
Best practices are recommendations that can help you use AWS CloudFormation more effectively and securely throughout its entire workflow.
The following best practices are based on real-world experience from current AWS CloudFormation customers.
>Organize Your Stacks By Lifecycle and Ownership
>Use Cross-Stack References to Export Shared Resources
>Use IAM to Control Access
Create EC2 instance (use https://onlineyamltools.com/prettify-yaml for formating the below yml )