How to Develop the CloudFormation Template for managing the EC2 and Security group?

Let’s go through the brief introduction about What is cloud formation service is useful and what is it for? If you have an experience when developing the AWS microservices project, you need to think about the many AWS resources. As well as you have to manging all the resources on your own. It’s a very mundane task. If you deploy your project services one by one separately it will take a lot of time. The cloud formation template is for you can automate your instance's management, Manage and create and provision all your service, Cognito management, and as well as the many other services using this template. You just need to configure the template. Other service management is depending on your template content. Using this template you can manage the backups for multiple regions. If you deploy your application in multiple development environments it also managed by this. You can configure using JSON format or YAML configuration. Before the configuration you need an AWS account, Have permission for AWS Cloudformation, and You’re familiar with YAML configuration. Let’s look into that approach to write the template.
Cloudformation template has different sections. Such as Resources, Parameters, Mappings, Conditions, Outputs, Metadata and etc. The Resources section is required. Others are optional. Let’s get into AWS resources.

The first task is to define the EC2 instances. According to the screenshot it’s only required parameter is ImageId. ImageId is referring to the AMI(Amazon Machine Images). You can use any AMIs. Ubuntu 16 is a free-tire version that I’m used in here. Also, you can use the properties called VPC properties. Such as securityGroupsIds and SubnetId. Eash instances can have multiple security groups. SubnetId will place the instance into a specific subnet in the VPC.

This SS shows the configure the instances name with security groups. You can have multiple security groups. This is how to manage the instance resource. Then lets the look at the configure the security groups. With these properties, we end up with a CloudFormation template that looks like:- Resource instance(figure3)
In order to add a Security Group, you will need to add GroupDescription, which is as expected a description of the security group. It's also a good idea to add the GroupName so that one is not automatically generated for you. Since this is in a VPC, we also need to define the VpcId property for our existing VPC.

After you created the template you just need to upload the AWS cloud formation template. It will read the template and compile all the resources allocated with the template. That’s it. Hopefully, these examples shed some light on how CloudFormation templates can be used to create EC2 instances and Security groups.