[AWS Lab] CloudFormation – VPC: Internet Gateway

In this lab, we will learn how to create an Internet Gateway and attach it to a VPC using CloudFormation.


0. Create a custom VPC

Please refer to this document: CloudFormation – VPC

  • Copy the VPC id

1. Create a Template File

  • Please review the following YAML template file and save it “myigw.yaml”.
AWSTemplateFormatVersion: 2010-09-09 
Description: Create an Internet Gateway and attach it to a VPC
Parameters:
  MyVpcId:
    Type: AWS::EC2::VPC::Id
    Description: 'Id of an existing VPC'
Resources:
  MyIGW:
    Type: AWS::EC2::InternetGateway
    Properties:
      Tags:
      - Key: env
        Value: dev
      - Key: Name
        Value: MyIGW
  AttachIGW:
    Type: AWS::EC2::VPCGatewayAttachment
    Properties:
      VpcId:
        Ref: MyVpcId
      InternetGatewayId:
        Ref: MyIGW
Outputs:
  IGWId:
    Description: The Internet Gateway ID
    Value: !Ref MyIGW


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 “myigw.yaml
    • Click “Next
  • Stack Details
    • Stack name: “IGW-Stack
    • parameters
      • MyVpcId: Select the id of the vpc that you created earlier
    • Click “Next
  • Stack Options
    • Accept all defaults
    • Click “Next
  • Review
    • Click “Submit

3. CloudFormation – Create Resources

  • The stack is creating an Internet Gateway.
    • Wait until the process completes.
  • Check the “Events” tab
  • Check the “Outputs” tab
    • You can see the igw id.
  • Check the “Resources” tab
    • Click the IGW id and check the properties

In the next part, we will create a route table.

Leave a Comment