0
0
AWScloud~10 mins

Internet Gateway for public access in AWS - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Internet Gateway for public access
Create VPC
Create Internet Gateway
Attach Internet Gateway to VPC
Create Public Subnet in VPC
Update Route Table
Add Route: 0.0.0.0/0 -> Internet Gateway
Launch Public Resources
Resources have public internet access
This flow shows how to create and attach an Internet Gateway to a VPC, then update routing so public subnet resources can access the internet.
Execution Sample
AWS
resource "aws_vpc" "main" {
  cidr_block = "10.0.0.0/16"
}

resource "aws_internet_gateway" "gw" {
  vpc_id = aws_vpc.main.id
}

resource "aws_route_table" "public" {
  vpc_id = aws_vpc.main.id

  route {
    cidr_block = "0.0.0.0/0"
    gateway_id = aws_internet_gateway.gw.id
  }
}
This code creates a VPC, an Internet Gateway attached to it, and a route table with a route sending all internet traffic to the gateway.
Process Table
StepActionResource Created/UpdatedState ChangeResult
1Create VPCaws_vpc.mainVPC with CIDR 10.0.0.0/16 createdVPC ready
2Create Internet Gatewayaws_internet_gateway.gwIGW created but not attachedIGW exists
3Attach IGW to VPCaws_internet_gateway.gwIGW attached to VPCVPC has IGW
4Create Route Tableaws_route_table.publicRoute table created for VPCRoute table ready
5Add Route 0.0.0.0/0 -> IGWaws_route_table.publicRoute added to send all traffic to IGWPublic route active
6Associate Route Table with Subnetaws_route_table_association.public_assocSubnet uses public route tableSubnet routes internet traffic
7Launch Public ResourcesEC2 instances in public subnetResources get public IP and routeResources have internet access
8End--Internet Gateway setup complete
💡 All steps complete, public subnet resources can access the internet via the Internet Gateway
Status Tracker
VariableStartAfter Step 1After Step 3After Step 5After Step 7Final
VPCNoneCreated with CIDR 10.0.0.0/16Attached IGWRoute table createdSubnet associatedReady with IGW and routes
Internet GatewayNoneCreatedAttached to VPCRoute added to route tableUsed by subnetActive for internet access
Route TableNoneNoneCreatedRoute 0.0.0.0/0 -> IGW addedAssociated with subnetRoutes internet traffic
SubnetNoneNoneNoneNoneCreated and associatedPublic subnet with internet access
Key Moments - 3 Insights
Why do we need to attach the Internet Gateway to the VPC?
Attaching the Internet Gateway to the VPC (Step 3) connects the VPC to the internet. Without this, the gateway exists but cannot route traffic for the VPC, so public access won't work.
What happens if we don't add the route 0.0.0.0/0 to the Internet Gateway?
Without the route (Step 5), the subnet's traffic won't know to use the Internet Gateway to reach the internet. So even if the gateway is attached, resources won't have internet access.
Why associate the route table with the subnet?
Associating the route table with the subnet (Step 6) tells the subnet to use the routes defined, including the internet route. Without this, the subnet uses the default route table which may not have internet access.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step is the Internet Gateway attached to the VPC?
AStep 2
BStep 5
CStep 3
DStep 6
💡 Hint
Check the 'Action' and 'State Change' columns in the execution table rows.
According to the variable tracker, what is the state of the Route Table after Step 5?
ARoute 0.0.0.0/0 -> IGW added
BRoute table created with no routes
CRoute table associated with subnet
DRoute table deleted
💡 Hint
Look at the 'Route Table' row under 'After Step 5' in the variable tracker.
If the route 0.0.0.0/0 -> IGW was missing, what would be the result?
AInternet Gateway would not be created
BSubnet traffic would not reach the internet
CResources still have internet access
DVPC would be deleted
💡 Hint
Refer to the key moment about the importance of the route in the execution table step 5.
Concept Snapshot
Internet Gateway connects a VPC to the internet.
Create IGW, attach to VPC.
Add route 0.0.0.0/0 in route table pointing to IGW.
Associate route table with public subnet.
Resources in subnet get internet access.
Full Transcript
This visual execution shows how to set up an Internet Gateway for public access in AWS. First, a VPC is created with a CIDR block. Then an Internet Gateway is created and attached to the VPC. A route table is created and a route is added to send all internet traffic (0.0.0.0/0) to the Internet Gateway. This route table is associated with a public subnet. Finally, resources launched in this subnet receive public IPs and can access the internet through the Internet Gateway. Key points include attaching the gateway to the VPC, adding the correct route, and associating the route table with the subnet to enable internet access.