Ravindra BagaleCourses & study guides मराठी Track your progress

Chapter 15: Amazon VPC — Subnets, Route Tables, NACL, NAT Gateway and Bastion Host

15.5 Internet gateway

In short: An internet gateway (IGW) is a horizontally scaled, redundant and highly available VPC component that connects your VPC to the internet.

The society's main gate – without it nobody comes in and nobody goes out. The Internet Gateway (IGW) is exactly that main gate. But note: putting up a gate does not give every wing a road – the road has to be written on the direction board. That is in the next lesson.

An internet gateway (IGW) is a horizontally scaled, redundant and highly available VPC component that connects your VPC to the internet. For an instance with a public IPv4 address, it translates between the instance's private IP and its public IP (one-to-one NAT). A VPC can have one internet gateway attached at a time, and the gateway itself has no charge (public IPv4 addresses are charged separately).

An instance can talk to the internet only when all four of these are true:

# Condition Where
1 An internet gateway is attached to the VPC VPC → Internet gateways
2 The subnet's route table has 0.0.0.0/0 → igw-... VPC → Route tables
3 The instance has a public IPv4 or an Elastic IP EC2 → Instances
4 The security group and the network ACL allow the traffic EC2 / VPC

Create and attach the internet gateway

  1. VPC → Internet gateways → Create internet gateway → Name tag society-igw → Create internet gateway.
  2. On the new gateway: Actions → Attach to VPC → choose society-vpc → Attach internet gateway.
  3. The State changes from Detached to Attached.
aws ec2 create-internet-gateway --tag-specifications 'ResourceType=internet-gateway,Tags=[{Key=Name,Value=society-igw}]'
aws ec2 attach-internet-gateway --internet-gateway-id igw-0123456789abcdef0 --vpc-id vpc-0123456789abcdef0

Ravindra Bagale's Tip

Many students create the IGW and forget Attach to VPC – the State stays Detached, and then it feels like "I did everything but there is no internet". As soon as you create the IGW, attach it and check that the State is Attached. Very simple, but people get it wrong a lot.

Lab

Chala, create society-igw and attach it to society-vpc. Then try to attach a second internet gateway to the same VPC and read the error: one VPC takes only one internet gateway at a time. Delete the extra gateway.