CloudFormation Designer
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
In the last blog post, we have created a CloudFormation template using YAML.
https://cloudaffaire.com/create-cloudformation-template/
In this blog post, we are going to create a CloudFormation stack using designers. The stack will contain VPC, subnet and one EC2 instance.
CloudFormation Designer
Step 1: Login to AWS console and navigate to ‘CloudFormation’.
Note: For shortening of the code, only has AMI mapping for APAC regions. Make sure you are in any one of the APAC region.
Step 2: Click ‘Create Stack’.
Step 3: Select ‘Create template in Designer’ and click ‘Create template in designer’.
Step 4: Change the name of your template and select YAML as the template language.
Step 5: In the ‘Parameters’ tab paste below YAML code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
Parameters: InstanceType: Description: WebServer EC2 instance type Type: String Default: t2.small AllowedValues: - t1.micro - t2.nano - t2.micro - t2.small - t2.medium ConstraintDescription: must be a valid EC2 instance type. KeyName: Description: Name of an EC2 KeyPair to enable SSH access to the instance. Type: 'AWS::EC2::KeyPair::KeyName' ConstraintDescription: must be the name of an existing EC2 KeyPair. |
Make sure indentation is correct, you can also use cloudformation_designer_demo.yaml from below GitHub repo.
https://github.com/CloudAffaire/CloudFormation
Note: Every time you make any changes to the template in the designer, it will ask for a refresh. Click on the refresh icon to refresh the designer.
Step 6: Click on ‘Mapping’ tab under ‘Components’ and paste below code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
Mappings: AWSInstanceType2Arch: t1.micro: Arch: HVM64 t2.nano: Arch: HVM64 t2.micro: Arch: HVM64 t2.small: Arch: HVM64 t2.medium: Arch: HVM64 AWSRegionArch2AMI: ap-northeast-1: HVM64: ami-06cd52961ce9f0d85 ap-northeast-2: HVM64: ami-0a10b2721688ce9d2 ap-northeast-3: HVM64: ami-0d98120a9fb693f07 ap-southeast-1: HVM64: ami-08569b978cc4dfa10 ap-southeast-2: HVM64: ami-09b42976632b27e9b ap-south-1: HVM64: ami-0912f71e06545ad88 |
Note: You can define other template elements as well by selecting the respective element tabs. Next, we will add resources to our template.
Make sure indentation is correct in the above code, you can also use cloudformation_designer_demo.yaml from below GitHub repo.
https://github.com/CloudAffaire/CloudFormation
Step 7: Expand ‘EC2’ resource type and drag ‘VPC’ to designer and in the ‘Properties’ tab, edit the name of the resource to ‘myVPC’.
Next, we are going to create the subnet which will host the EC2 instance.
Step 8: Drag ‘Subnet’ under ‘myVPC’ in designer and in the ‘Properties’ tab, edit the name of the resource to ‘mySUBNET’.
Observe: Designer has automatically assigned VPC id reference of ‘myVPC’ to ‘mySUBNET’ VpcId property. Hence ‘mySUBNET’ will be created under ‘myVPC’.
Step 9: Drag ‘Instance’ under ‘mySUBNET’ in designer and in the ‘Properties’ tab, edit the name of the resource to ‘myINSTANCE’.
We have previously defined parameters and mapping for our template. To make the resources use those, we need to manually update the resource section of the template code.
Step 10: Update the resource properties under ‘Template’.
myVPC:
1 2 3 4 |
CidrBlock: 10.0.0.0/16 Tags: - Key: "Name" Value: "myVPC" |
mySUBNET:
1 2 3 4 5 |
VpcId: !Ref myVPC CidrBlock: 10.0.0.0/24 Tags: - Key: "Name" Value: "mySUBNET" |
myINSTANCE:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
InstanceType: !Ref InstanceType ImageId: !FindInMap - AWSRegionArch2AMI - !Ref 'AWS::Region' - !FindInMap - AWSInstanceType2Arch - !Ref InstanceType - Arch KeyName: !Ref KeyName SubnetId: !Ref mySUBNET Tags: - Key: "Name" Value: "myInstance" |
Note: Make sure your code indentation is correct or you will get an error. You can also use cloudformation_designer_demo.yaml from below GitHub repo.
https://github.com/CloudAffaire/CloudFormation
Our template is ready for deployment. Next, we are going to create a stack using this template.
Step 11: Click on the cloud icon to upload this template in S3 and create a stack.
You will be redirected to stack creation window.
Step 12: Provide the parameters for your stack and create the stack.
Step 13: Cleanup.
Note: This will also delete the underlying resources for this stack.
Hope you have enjoyed this article. In the next blog post, we will discuss intrinsic functions in CloudFormation.
To get more details on CloudFormation, please refer below AWS documentation
https://docs.aws.amazon.com/cloudformation/index.html
I need help plis