← Back to Labs
Intermediate00:55:00

How to Create Virtual Private Cloud (VPC) with AWS CloudFormation

Task 1

Task 1: Sign in to AWS Management Console

↑ Top
  1. Click on the Open Console button, and you will get redirected to AWS Console in a new browser tab.
  2. On the AWS sign-in page, Leave the Account ID as default. Never edit/remove the 12 digit Account ID present in the AWS Console. otherwise, you cannot proceed with the lab. Now copy your User Name and Password in the Lab Console to the IAM Username and Password in AWS Console and click on the Sign in button.
  3. On the AWS sign-in page,
  4. Leave the Account ID as default. Never edit/remove the 12 digit Account ID present in the AWS Console. otherwise, you cannot proceed with the lab.
  5. Now copy your User Name and Password in the Lab Console to the IAM Username and Password in AWS Console and click on the Sign in button.
  6. Once Signed In to the AWS Management Console, Make the default AWS Region as US East (N. Virginia) us-east-1.
  7. Note : If you face any issues, please go through FAQs and Troubleshooting for Labs.
Task 2

Task 2: Creating Subnets using the VPC Template cloudformation stack

↑ Top
  1. In this task , we will be creating VPC stack using the pre-created cloudformation template in the S3 bucket.
  2. Search for S3 by click on Services in the top menu, then click on S3 in the Storage section. You will see a bucket name starting with "lab" with numeric digits appended to the end, like lab1234564543. Open that bucket and click on the object named VPC_template.json. Next, copy the Object URL to the clipboard for use in the CloudFormation template.
  3. Search for S3 by click on Services in the top menu, then click on S3 in the Storage section.
  4. You will see a bucket name starting with "lab" with numeric digits appended to the end, like lab1234564543.
  5. Open that bucket and click on the object named VPC_template.json.
  6. Next, copy the Object URL to the clipboard for use in the CloudFormation template.
  7. Task 2: Creating Subnets using the VPC Template cloudformation stack
  8. Navigate to CloudFormation by clicking on Services in the top menu, click on CloudFormation in the Management and Governance section.
  9. Then click on Create Stack and select Choose an existing template.
  10. Choose Amazon S3 URL in Specify template. Then paste the Object URL below.
  11. Click on Next
  12. Task 2: Creating Subnets using the VPC Template cloudformation stack
  13. Stack Name: Enter MyStack123 and click on Next
  14. Task 2: Creating Subnets using the VPC Template cloudformation stack
  15. On Tag option, click Add new tag.
  16. Key: Enter Name
  17. Value: Enter MyCF
  18. Task 2: Creating Subnets using the VPC Template cloudformation stack
  19. Leave other options as default and click on Next
  20. Review the Stack details and click on Submit. Then you will be redirected to the CloudFormation Stack list.Note: You need to wait 5-10 minutes to complete the stack resource creation.
  21. Review the Stack details and click on Submit. Then you will be redirected to the CloudFormation Stack list.
  22. It will display CREATE_COMPLETE.
  23. Navigate to the Services menu in the top, click on VPC in the Networking and Content Delivery section.
  24. You can see the vpc resources created by CloudFormation.
Task 3

Task 3: Creating Subnets using the VPC II Template cloudformation stack

↑ Top
  1. Search for S3 by clicking on Services in the top menu, then click on S3 in the Storage section. You will see a bucket name starting with lab with numeric digits appended to the end, like lab1234564543. Open that bucket and click on the object named VPC_II_template.json. Now, copy the Object URL to the clipboard for use in CloudFormation template.
  2. Search for S3 by clicking on Services in the top menu, then click on S3 in the Storage section.
  3. You will see a bucket name starting with lab with numeric digits appended to the end, like lab1234564543.
  4. Open that bucket and click on the object named VPC_II_template.json.
  5. Now, copy the Object URL to the clipboard for use in CloudFormation template.
  6. Task 3: Creating Subnets using the VPC II Template cloudformation stack
  7. Click on Services in the top menu, then click on CloudFormation in the Management and Governance section
  8. Select the stack MyStack123 and click on Update stack and select Make a direct update from dropdown.
  9. Task 3: Creating Subnets using the VPC II Template cloudformation stack
  10. Select Replace existing template and paste the URL below in the Amazon S3 URL.
  11. Click on Next. You should see No Parameters being displayed. Then, click on Next.
  12. Tags - No changes needed in this page, click on Next button.
  13. Review the stack details and click on Submit .
  14. Click on Events and it will display extra space UPDATE_IN_PROGRESS.
  15. Task 3: Creating Subnets using the VPC II Template cloudformation stack
  16. Once your stack status changes to UPDATE_COMPLETE, we can proceed forward.
  17. Click on the Output tab. You can see an additional Availability Zone displayed with a different value than the original Availability Zone.
  18. Task 3: Creating Subnets using the VPC II Template cloudformation stack
  19. Click on Services in the top menu, click on VPC in the Networking and Content Delivery section.
  20. Select the VPC named Lab VPC in the list and click on Subnets in the left panel.
  21. You will now see your subnets. The VPC has been updated with a new stack.
  22. Task 3: Creating Subnets using the VPC II Template cloudformation stack
Task 4

Task 4: Deep dive into the VPC_Template and VPC_II_Template

↑ Top
  1. In the present lab, we have used two templates for stack creation. They are VPC_Template and VPC_II_Template.
  2. When you download and open the template,here is how the VPC_template.json looks like,
  3. Task 4: Deep dive into the VPC_Template and VPC_II_Template
  4. In the above image, we are first creating a VPC with the name Lab VPC, CIDR block- 10.0.0.0/16. Then an internet gateway with the name Lab Internet Gateway is created. Lab VPC is then attached to the Lab Internet Gateway.
  5. We then are creating a public subnet named public subnet 1 in availability zone 1 with the IP address 10.0.0.0/24. The private subnet is created (named private subnet 1)with IP address 10.0.1.0/24 in the AZ-1.
  6. Task 4: Deep dive into the VPC_Template and VPC_II_Template
  7. After the subnets are created then a public route table is created. The public subnet 1 is then associated with the public route table.
  8. Task 4: Deep dive into the VPC_Template and VPC_II_Template
  9. A private route table then is created. The private subnet1 is then associate with the private route table. (We can find the subnet associations option in route table and add the required subnet in the console).
  10. Mystack123 is then created executing all the required resources. After that, you are updating the stack template with VPC_II_Template.
  11. When you download and open the second template VPC_II_template.json. that is present in the s3 bucket. You are creating a VPC with 2 public subnets and 2 private subnets.VPC is named Lab VPC similar to the above-created stack. An internet gateway is attached to the VPC. The public subnets used here are public subnet 1 (10.0.0.0/24) and public subnet 2 (10.0.2.0/24). The private subnets are private subnet1 (10.0.1.0/24) and private subnet2 (10.0.3.0/24) respectively. The public subnets are associated with the public route table and private subnets are associated with the private route table. The main difference is public subnet 1 and private subnet 1 are created in the same availability zone ie; AZ-1 and private subnet and public subnet 2 are created in AZ-2.
  12. New resources are created after the stack is updated.Do You Know ?AWS CloudFormation provides a powerful feature called custom resources, which allows you to extend the capabilities of CloudFormation templates by adding your own resource types. These custom resources can be created and managed using AWS Lambda functions.
  13. New resources are created after the stack is updated.
  14. AWS CloudFormation provides a powerful feature called custom resources, which allows you to extend the capabilities of CloudFormation templates by adding your own resource types. These custom resources can be created and managed using AWS Lambda functions.
Task 5

Task 5: Validation Test

↑ Top
  1. Once the lab steps are completed, please click on the Validation button on the left side panel.
  2. This will validate the resources in the AWS account and displays whether you have completed this lab successfully or not.
  3. Sample output :
  4. Task 5: Validation Test
  5. You have successfully deployed an AWS CloudFormation template that creates an Amazon VPC
  6. You have successfully examined the components in the template
  7. You have successfully updated a CloudFormation stack
  8. You have successfully examined a template with the AWS CloudFormation Designer.
  9. You have successfully validated the lab.
  10. Sign out from the AWS Management Console.
  11. Click on End Lab button from the lab console and wait till the process gets completed.
← Back to Labs