Some text some message..
Back 3. AWS INFRASTRUCTURE PIPELINE (VPC-Subnets-Internet Gateway-Route) 12 Nov, 2025


InternetGateway:

    Type: AWS::EC2::InternetGateway

  AttachGateway:

    Type: AWS::EC2::VPCGatewayAttachment

    Properties:

      VpcId: !Ref MyVPC

      InternetGatewayId: !Ref InternetGateway

  RouteTable:

    Type: AWS::EC2::RouteTable

    Properties:

      VpcId: !Ref MyVPC

  PublicRoute:

    Type: AWS::EC2::Route

    DependsOn: AttachGateway

    Properties:

      RouteTableId: !Ref RouteTable

      DestinationCidrBlock: 0.0.0.0/0

      GatewayId: !Ref InternetGateway

  RouteAssoc1:

    Type: AWS::EC2::SubnetRouteTableAssociation

    Properties:

      SubnetId: !Ref Subnet1

      RouteTableId: !Ref RouteTable

  RouteAssoc2:

    Type: AWS::EC2::SubnetRouteTableAssociation

    Properties:

      SubnetId: !Ref Subnet2

      RouteTableId: !Ref RouteTable


Now we’re entering the “network connectivity” section of AWS CloudFormation template — this is what actually connects your private VPC and subnets to the internet 🌐.

Let’s go step by step — we’ll visualize it like you’re wiring up your own mini data center.


🧠 OVERVIEW — What this block does

This part sets up:

  1. Internet Gateway → door from your VPC to the internet 🌍

  2. AttachGateway → connects that door to your VPC 🏠

  3. RouteTable → defines which traffic goes where (the “roadmap”) 🗺️

  4. PublicRoute → says: “If traffic goes to the internet (0.0.0.0/0), send it through the gateway.” 🚦

  5. Subnet Associations (RouteAssoc1 & 2) → link your subnets to that route table so they can use the internet.


🌍 1️⃣ Internet Gateway

InternetGateway:
  Type: AWS::EC2::InternetGateway

💬 Explanation

  • Creates an Internet Gateway (IGW) — think of it as the main door between your AWS VPC and the Internet.

  • Without this, your VPC is like an island with no bridge — it can’t send or receive internet traffic.

Purpose:
Provides your VPC access to the public internet.

🧠 Analogy:

Internet Gateway = Broadband router of your AWS home.


🔗 2️⃣ Attach the Gateway to the VPC

AttachGateway:
  Type: AWS::EC2::VPCGatewayAttachment
  Properties:
    VpcId: !Ref MyVPC
    InternetGatewayId: !Ref InternetGateway

💬 Explanation

  • Just creating an IGW doesn’t automatically attach it — it’s a separate step.

  • This resource attaches the InternetGateway you created to your MyVPC.

Purpose:
Connects the “door” (IGW) to your “house” (VPC), allowing traffic to flow through.


🗺️ 3️⃣ Route Table

RouteTable:
  Type: AWS::EC2::RouteTable
  Properties:
    VpcId: !Ref MyVPC

💬 Explanation

  • A Route Table is like a map that defines where network traffic should go.

  • Each subnet must be associated with one.

  • Since you’re making a public route table, it will contain a route to the internet via the IGW.

Purpose:
Holds routing rules for your subnets.

🧠 Analogy:

Route Table = Road directory that says “traffic to this destination → go through this path.”


🚦 4️⃣ Public Route (Internet Access Rule)

PublicRoute:
  Type: AWS::EC2::Route
  DependsOn: AttachGateway
  Properties:
    RouteTableId: !Ref RouteTable
    DestinationCidrBlock: 0.0.0.0/0
    GatewayId: !Ref InternetGateway

💬 Explanation

  • This adds a route entry to your route table.

  • DestinationCidrBlock: 0.0.0.0/0 means “any IP address anywhere in the world.”

  • GatewayId: !Ref InternetGateway means “send that traffic to the Internet Gateway.”

  • DependsOn: AttachGateway ensures that the gateway is attached before this route is created.

Purpose:
Makes all outgoing traffic from your subnets (like ECS containers or EC2 instances) go through the Internet Gateway to reach the internet.

🧠 Analogy:

This is the rule that says “If you’re leaving the neighborhood, use the main highway (Internet Gateway).”


🕸️ 5️⃣ Associate Route Table with Subnet 1

RouteAssoc1:
  Type: AWS::EC2::SubnetRouteTableAssociation
  Properties:
    SubnetId: !Ref Subnet1
    RouteTableId: !Ref RouteTable

💬 Explanation

  • This binds Subnet 1 with your Route Table.

  • Meaning: Subnet 1 will follow the routes defined there (including internet access).

Purpose:
Gives Subnet 1 access to the internet through the Internet Gateway.


🕸️ 6️⃣ Associate Route Table with Subnet 2

RouteAssoc2:
  Type: AWS::EC2::SubnetRouteTableAssociation
  Properties:
    SubnetId: !Ref Subnet2
    RouteTableId: !Ref RouteTable

💬 Explanation

  • Same logic as above, but for Subnet 2.

  • So both subnets (in two different Availability Zones) share the same public route table and have internet connectivity.

Purpose:
Ensures Subnet 2 also has public internet access.


🌐 ✅ END RESULT — What You’ve Built

Component Type Description
InternetGateway AWS::EC2::InternetGateway Door to the internet
AttachGateway AWS::EC2::VPCGatewayAttachment Attaches that door to your VPC
RouteTable AWS::EC2::RouteTable Traffic rules (map) for your subnets
PublicRoute AWS::EC2::Route Rule saying “send all 0.0.0.0/0 traffic to Internet Gateway”
RouteAssoc1 & 2 AWS::EC2::SubnetRouteTableAssociation Connects both subnets to that route table (so they can use the internet)

🧭 Visual Summary

Here’s what your network looks like now:

                 🌍 Internet
                     │
             ┌─────────────────┐
             │ Internet Gateway │
             └──────┬───────────┘
                    │
        ┌───────────────────────────────┐
        │           VPC (10.0.0.0/16)   │
        │                               │
        │   ┌────────────────────┐      │
        │   │  Subnet 1 (AZ A)   │────┐ │
        │   │ 10.0.1.0/24        │    │ │
        │   └────────────────────┘    │ │
        │                             │ │
        │   ┌────────────────────┐    │ │
        │   │  Subnet 2 (AZ B)   │────┘ │
        │   │ 10.0.2.0/24        │      │
        │   └────────────────────┘      │
        │                               │
        │   Route Table: 0.0.0.0/0 → IGW│
        └───────────────────────────────┘

💡 TL;DR Summary

Concept Explanation Example
Internet Gateway Connects VPC to the internet Doorway to outside world
VPC Gateway Attachment Attaches IGW to VPC Connects your “door”
Route Table Defines traffic directions Like a city’s road map
Public Route Tells where “internet traffic” goes 0.0.0.0/0 → IGW
Subnet Associations Subnets use that route table Subnet1 & 2 can now access internet