How to Fix AWS VPC Subnet No Internet Gateway
In this tutorial, you'll learn about How to Fix AWS VPC Subnet No Internet Gateway. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.
Instances in your subnet cannot reach the internet — there is no Internet Gateway attached or the route table does not point to it.
Step-by-Step Fix
1. Check if an Internet Gateway exists
aws ec2 describe-internet-gateways --filters Name=attachment.vpc-id,Values=vpc-12345678
If no results, create one:
aws ec2 create-internet-gateway
Expected output:
{
"InternetGateway": {
"InternetGatewayId": "igw-12345678"
}
}
2. Attach the Internet Gateway to the VPC
aws ec2 attach-internet-gateway --internet-gateway-id igw-12345678 --vpc-id vpc-12345678
3. Check the route table
aws ec2 describe-route-tables --filters Name=vpc-id,Values=vpc-12345678
4. Add a default route to the Internet Gateway
aws ec2 create-route --route-table-id rtb-12345678 --destination-cidr-block 0.0.0.0/0 --gateway-id igw-12345678
5. Verify subnet association
aws ec2 describe-subnets --subnet-ids subnet-12345678 --query 'Subnets[0].RouteTable'
6. Test internet connectivity
aws s3 ls
Common Mistakes
| Mistake | Fix |
|---|---|
| No Internet Gateway in the VPC | Create and attach an IGW |
| Route table has no 0.0.0.0/0 route | Add a default route to the IGW |
| Subnet is not associated with the route table | Associate the subnet with the correct route table |
| NACL blocks outbound traffic | Check network ACL outbound rules |
| Instance has no public IP | Enable auto-assign public IP on the subnet |
Prevention
- Use a default VPC for development (it comes preconfigured).
- Add Internet Gateway during VPC creation.
- Use NAT Gateway for private subnets.
- Document VPC architecture with route table mappings.
Common Mistakes with vpc subnet
- Forgetting
deriving (Show, Eq)on custom data types needed for debugging - Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
- Using
headandtailinstead of pattern matching, causing runtime errors on empty lists
These mistakes appear frequently in real-world AWS code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro