Cloud Computing Introduction
AWS Introduction

AWS CloudFormation (Hands-on)

AWS CloudFormation (Hands-on)
play-rounded-fill
 
Welcome back friends. In this video we will do hands on with cloud formation. It says that using AWS cloud formation we can model and provision cloud infrastructure. It provides a common language to describe and provision all the infrastructure resources in your environment in a safe, repeatable way. Cloud formation is based on the concept of infrastructure as a code. What it means, we provide code to cloud formation, which is called template in the cloud formation term. Using that template, cloud formation creates stack, which is essentially creating AWS resources. That being said, first we are going to create a cloud formation stack. Now the first thing we need to make sure that we are in the Northern Virginia AWS region to create the stack, otherwise, the cloud formation template that we are using may not work. We have 3 choices here. We can upload our own template. Use a sample template or create a template in Designer. I have a template ready to use, so I'm going to use the template which I already have. Next, here, either we can say that template is on S3 or we can directly upload the file. I'm going to upload the template file. This template is going to create an EC2 instance. Let's take a look at what is in the template. It's a Yamal file which is easy to understand. We are going to launch an EC2 instance using this template. First is the name of the resource. The name for the resource we have given here is my instance. We need to tell what is the type of resource, which is the EC2 instance. We need to define some properties for the resource. It is going to be launched in the availability zone US East 1A. We need to provide the image ID, which is AMI ID and the instance type, which is T2 micro. This is the template definition. Using this template, cloud formation will create stack for us. It means essentially it will create AWS resources. Click on next. Here we need to provide the template name. I'll provide the template name. I'll copy and paste here the template name just to save some typing. Here we can provide parameters, but since there are no parameters defined in my template, I don't have to do anything here. Click on next. Here we can provide some tags. Let's provide a tag for tag key. We can provide name and for value. Let's enter EC2 instance cloud formation template. Let's scroll down, the default options are OK. Click on next. Here, let's review what we have. Scroll down. It looks fine. Click on submit. Here we can look into what we have uploaded as a template. This template is going to be used to create an EC2 instance. As you can realize, this is why cloud formation is called infrastructure as code. You provide code for what infrastructure you want, and cloud formation based on the code will create infrastructure for you, such as EC2 instance, RDS instance, S3 bucket, etc. You can also view it in the designer. If we go to the EC2 instance, we can notice that cloud formation is creating an EC2 instance based on the template.
If we click on events, we can see all the events that are being executed by
the cloud formation template. As you can see, the instant status is resource creation initiated. Here we have various tabs. For example, if you go to the Resources tab, you can see the resources getting created You can notice that an EC2 instance, my instance, is getting created, and status is marked as complete now. This means the EC2 instance has been launched successfully, as you can see, it says Crem complete. If you click on the stack Info tab, we can find information about the stack. Let's scroll down here. All the detail about the stack is given. Also, you can update the stack. You can replace the current template. Let's update the template by uploading a new template file. Click on the chosen file.
I'll select this template.
If you look at this template, this template has more code than our previous template. Here we have parameters, resources, elastic IP, and two security groups. These two security groups we are going to attach to the EC2 instances. As you can see these two security groups are referred to in the resource section of the template. As you can realize this is relatively more complicated, but cloud formation is smart enough to figure out how to manage dependency. What should be created first and what should be created next to update the stack? What I mean, how to create things in the correct order. Now let's click on the next. Here in this template we are using parameters. The parameter name is security group description. Let me provide the custom value for this parameter. Let me enter cloud formation, demo Security Group. Click on next. On this page, everything is fine. We don't need to make any changes on this page.
Click on next.

Here we can review, click on submit on this page.
As you can see based on the new template we uploaded, cloud formation is going to create Elastic IP and two security groups and going to update this instance as it says replace. In this example, cloud formation will terminate the previously launched EC2 instance. The green color is the new one means cloud formation will create resources. And the blue color means the resources will be updated. So we are good with these changes. Let's click on submit to update the stack. As you can notice on the events tab, the latest event status is Update in Progress So cloud formation will make all the necessary changes behind the scenes to what we have specified through the template. Let's go to the EC2 instances page to see how the progress is made. As we can see, it is initializing the instance, and our previous instance is running, which will be terminated later on when the new instance is up. We can go to the designer. We can notice that the EC2 instance is attached to two security groups and has been assigned elastic IP. This is a nice way to visualize the stack. Let's refresh here. Now the update is complete, and delete is complete as well means the previous instance is deleted. If we go to the EC2 instance page, we see only one instance, the new instance The previous one is now terminated. As you can realize, this is the power of cloud formation. We have to just provide the code. The cloud formation will take care of ordering and dependency and create the right infrastructure for us based on the template. Let's click on the resources tab. It shows the status of all the resources that are getting created by our cloud formation template. As you can see, 2 security groups have been created. My instance is updated and Elastic IP is created. We can click on the other tabs. The parameter tab shows the parameter we provided. The template tab shows the template. Stack Info tab is showing detailed information about the stack. Finally, if we need to delete the resources, we don't need to go to each resource and delete them individually. If we just click on the delete, the cloud formation will do the necessary cleanup to delete all the resources that were created by the template. Cloud formation will figure out in which order the resources need to be deleted.
This is very good as we can clean up by ourselves very easily and we are
done with this hands-on demo. To summarize, cloud formation is a useful service for creating AWS resources using the template, which is based on the concept of infrastructure as a code. The beauty is you can use the same template to deploy in the other AWS regions or other AWS accounts to create the resources quickly for you. You just need to write a well written template, and cloud formation will do the rest for you. It means creating necessary resources based on the template, which is infrastructure as a code
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

Hide picture