Do You Need an IGW for Internet Access with EC2 Instance and EIP?

amazon-vpcamazon-web-services

I’m confused about Internet Gateway in AWS, if it says that in order for your VPC to access the internet you need a IGW why then when you create a EC2 instance with an EIP you automatically have access to the internet.

I then have this question that I haven't been able to answer:

Why then when you create an EC2 instance (which is created in the default VPC) in AWS and you assign an elastic IP you automatically have access to the internet if in the AWS documentation says that in order for your VPC to have access to the internet you need an Internet Gateway?

Best Answer

A VPC requires an Internet Gateway (IGW) to communicate with the internet. A Virtual Private Gateway (VPN endpoint) can let you communicate with other networks such as corporate networks via a VPN, which could potentially give you an internet connection. VPC endpoints and PrivateLink give you other limited connectivity, such as private connectivity to S3, which usually goes over the Internet.

You can have a public IP address auto assigned without having an internet gateway. If you try to assign an Elastic IP to your instance when the VPC doesn't have an Internet Gateway it won't let you - the error message is

Network vpc-05054501693f2f5fb is not attached to any internet gateway

If you try to detach an internet gateway from a VPC that has an instance with an EIP you get this error message.

Detatch Error

I just tested all this to be double sure. It only took ten minutes to create a VPC and mess around a bit. That's the great thing about cloud / AWS, it's generally easy to work things out by trying them. It probably cost me $0.05.

Related Topic