AWS CloudFormation Exercise 6: VPC creation

Exercise 6: Cloud Formation Template for VPC

In This Exercise, we are going to configure VPC using the Cloud Formation Template written in YAML format.

We are going to create a VPC in Mumbai Region (ap-south-1), with 4 subnets spread across two availability zone i.e. ap-south-1a and ap-south-1b. Out of 4, two of them are public and the remaining two are private subnets. Two route tables will be created, one for the public subnets and another for the private subnets.  Internet gateway and Nat gateway will be created and route table entries will be added in the respective route tables.

To get the Stack click on the link: https://github.com/pranavdhopey

and save it to server say under /opt directory.

1.   Login to AWS Management Console. AWS Console

2.   On Management Console click on “Cloud Formation” under the “Management and Governance” section.

3.   Now you will land on Cloud Formation Console. In Cloud Formation Console click on the “Create Stack” button.

Now follow the below steps to create a stack for this exercise

Step 1: Specify template

In this section choose the “Template is Ready” button and select “Upload a template file”. Now choose a file to upload from your personal computer where it is saved and upload. Now click on next.

Step 2: Specify stack details

Now Specify “Stack name” for e.g. Say “TestVPC” for this exercise. Now provide the values for parameters need to create VPC stack, here we are giving the below parameter values.

1. VpcCIDR: 192.168.0.0/16 (Values to be replace)

2. PublicSubnet1CIDR: 192.168.0.0/24 (Values to be replace)

3. PublicSubnet2CIDR: 192.168.1.0/24 (Values to be replace)

4. PrivateSubnet1CIDR: 192.168.11.0/24 (Values to be replace)

5. PrivateSubnet2CIDR: 192.168.12.0/24 (Values to be replace)

6. EnvironmentName: Dev/Test/Prod

Step 3: Configure stack options

On the “Configure stack options” page leave all settings default and click on next.

Step 4: Review Stack

In this step review all the settings that you have filled in and then click create stack.

After some time stack will be created and you can view and access resources created by the cloud formation stack.

Click below to get started

Create Stack

 

We can also create a stack using AWS CLI

AWS CLI for creating stack:

Note: Replace Template file name accordingly.

1.   To validate cloud formation template template

#aws cloudformation validate-template --template-body file:///<path-to-file>/

CFNVPCConfigurationStack.yml

 

2.   To create stack

#aws cloudformation create-stack --stack-name TestVPC --template-body file:///

<path-to-file>/CFNVPCConfigurationStack.yml --parameters file:///<path-to

file>/parameters.json

Here parameters are passed in “parameters.json” file to avoid a mess on the command line. Snapshot is given below.




3.   To describe stack

#aws cloudformation describe-stacks --stack-name TestVPC


4.   To view the stack events

#aws cloudformation describe-stack-events --stack-name TestVPC


5.   To delete the stack

#aws cloudformation delete-stack --stack-name TestVPC


This completes VPC creation using a cloud formation template with various parameters.

 

No comments:

Post a Comment