[AWS Lab] CloudFormation – VPC

In this lab, we will learn how to create a custom VPC using CloudFormation.


1. Create a Template File

  • Please review the following YAML template file and save it “myvpc.yaml”.
AWSTemplateFormatVersion: 2010-09-09 
Description: Create a custom VPC
Resources:
  MyVPC:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: 10.0.0.0/16
      EnableDnsSupport: 'true'
      EnableDnsHostnames: 'true'
      Tags:
      - Key: env
        Value: dev
      - Key: Name
        Value: MyVPC
Outputs:
  VPCID:
    Description: The VPC ID
    Value: !Ref MyVPC

2. CloudFormation – Create a Stack

  • Click “Create stack
    • Click “with new resources (standard)
  • Create Stack
    • Check “Template is ready
    • Check “Upload a template file
      • Choose “myvpc.yaml
    • Click “Next
  • Stack Details
    • Stack name: “VPC-Stack
    • No parameters
    • Click “Next
  • Stack Options
    • Accept all defaults
    • Click “Next
  • Review
    • Click “Submit

3. CloudFormation – Create Resources

  • The stack is creating a custom VPC.
    • Wait until the process completes.
  • Check the “Events” tab
  • Check the “Outputs” tab
    • You can see the vpc id.
  • Check the “Resources” tab
    • Click the VPC link to view the newly created VPC.
      • Check the CIDR, Main route table, and Maine NACL.

4. Check Created Resources

The custom VPC comes with some default settings.

  • Subnets
    • None
  • Route Table
    • Local route
      • Destination: 10.0.0.0/16
      • Target: local
  • Network ACL
    • Inbound rules
      • Allow all traffic
    • Outbound rules
      • Allow all traffic
  • Security Group
    • Inbound rules
      • Allow input traffic only from the same security group
    • Outbound rules
      • Allow all output traffic

In the next part, we will create an Internet Gateway and attach it to the VPC.

Leave a Comment