In the previous post, I shared about what is cloud formation and also whether we should learn about it. If you coming from the previous post, I am happy for you that you "Find Your Why" to learn about AWS CloudFormation.
However if you're still wondering whether you need to learn it, take a look at the post and "Find Your Why".
Besides, I also share the template structure of Cloud Formation and how to launch an EC2 Instance using the Cloud Formation template. So in this post, I will be taking another minimal step - which is adding a security group into the existing EC2 instance.
Without further ado, let's start.
We created an EC2 Instance using the Cloud Formation template in the previous post. Refer to the gist below for the template code.
In this tutorial, we will be adding a security group to the TestInstance (EC2 Instance). **Here are the **requirements for this tutorial.
Below is the structure we will be using for the Security Group. Here is the explanation for each field of the configuration.
At this point, you might have already write the part where you create the Security Group Resource. Next, we will need to assign the security group to the EC2 Instance.
You can use
!Ref the shorthand syntax in yaml to assign the security group to EC2 Instance. Below is an example of how you can use
We will be taking the LogicalID for the resource we name in the template. So in this scenario, it will be
It's the time where we shall do some hands-on and enhance our learning.
You can find the existing CloudFormation code here and add the security group resource and continue the tutorial.
If you're stuck, you can refer to the final answer here.
Here are the expected output. From the screenshot below, we created a security group which allowing port 80 (HTTP) **and **port 443 (HTTPS).
Last but not least, you also have to ensure the security group assigned to your EC2 Instance. You can find that from your EC2 Instance Dashboard. Refer to the screenshot below.
In this post, I shared how to provision Security Group via CloudFormation and most importantly how to use
!Ref to assemble the relationship between resources such as