7.1 VPC Overview
Last updated
Was this helpful?
Last updated
Was this helpful?
Think of a VPC as a virtual data center in the cloud. Whenever we have been deploying the EC2 instances, we have been doing that into our default VPCs, so every Region in the world has a default VPC, and you get that set up when you first set up your AWS account, Amazon provide it for you automatically.
Amazon Virtual Private Cloud (VPC) lets you provision a logically isolated section of the AWS cloud where you can launch AWS resources in a virtual network that you define. You have complete control over your virtual networking environment, including selection of your own IP address range, creation of subnets, and configuration of route tables and network gateways.
You can easily customize the network configuration for your Amazon Virtual Private Cloud. For example, you can create a public-facing subnet for your web servers that has access to the Internet, and place your backend systems such as databases or application servers in a private-facing subnet with no Internet access. You can leverage multiple layers of security, including security groups and network access control lists, to help control access to Amazon EC2 instances in each subnet.
Additionally, you can create a hardware virtual private network (VPN) connection between your corporate datacenter and your VPC and leverage the AWS cloud as an extension of your corporate datacenter.
Here is a diagram of VPC to show its structure:
Internet Gateway is for the connection from the whole Internet. The virtual private gateway is for the connection from a VPN.
Network ACL stands for network access control list.
SN stands for subnet. Public SN means it has Internet access. Private SN means it is only accessible via VPN or some other mechanism. You could go in through the Internet and then SSH from your public into your private.
Obviously, one Subnet always equals one Availability Zone.
Amazon basically allow you to use a bunch of different internal IP address ranges. There is a website called "CIDR.xyz", which can help you to visualize the IP address and CIDR range. You can use:
10.0.0.0 - 10.255.255.255 (10/8 prefix)
172.16.0.0 - 172.31.255.255 (172.16/12 prefix)
192.168.0.0 - 192.168.255.255 (192.168/16 prefix)
At most you can go up to with Amazon is /28. That is the smallest IP address range that you can have with Amazon, and that will give you a count of 16 IP addresses.
You can have multiple VPCs inside a Region. The soft limit is 5 VPCs in one Region, but you can email AWS to increase it.
We learnt that VPC is basically a virtual data center in the cloud, and we can create subnets and each subnet can go into different AZs and then our subnets can have different network address (for example, 10.0.1.0/24 and 10.0.2.0/24, etc).
What we can do with VPC:
Launch instances into a subnet of your choosing
Assign custom IP address ranges in each subnet
Configure route tables between subnets
Create Internet Gateway and attach it to our VPC. Be aware that you can only have one Internet Gateway per VPC. Internet Gateways by default is highly available, so they are spread across all availability zones.
Much better security control over your AWS resources. This is because you can use things like (private) subnets to block traffics, or you can use things like network ACL to block specific IP addresses.
Instance security groups. We can deploy inside our VPC. Remember a security group can span availability zones. You can have a security group across multiple availability zones and therefore by the definition you can have security groups spanning multiple subnets as well.
Subnet network access control lists (ACLS). Using these ways that you can go in and block IP addresses.
Default VPC is user friendly, allowing you to immediately deploy instances. Amazon provision that for us in every single Region when we first set up our account. At the beginning, a default VPC components including:
VPC with a size /16 IPv4 CIDR block (172.31.0.0/16), this provides up to 65536 private IPv4 addresses.
Default subnet in each AZ with size /20. This provides 4096 addresses per subnet (but 5 reserved for each subnet).
Internet Gateway.
Main Route Table with a rule dest: 0.0.0.0/0, target: IGW-ID.
Security Group associated with default VPC.
NACL associated with default VPC.
Associate the default DHCP options set for your AWS account with your default VPC.
At the beginning, a custom VPC components including:
VPC with a size you defined.
Main Route Table has a rule dest: 10.0.0.0/16, target: local which allows the traffic within the VPC only.
NACL. This is a private NACL which deny all inbound and outbound traffic.
Security Group. It allows all outbound traffic but deny all inbound traffic.
All subnets in default VPC have a route out to the Internet (Internet accessible by default).
Each EC2 instance has both a public and private IP address when we deploy them into our default VPC. But if we have a custom VPC and if we have a private subnet, we will not get a public IP address. We will only get a private IP address. You need to go to the subnet (usually a public subnet), click Actions -> Modify Auto-assign IP settings. If you didn't set it, you still can assign Elastic IP to the instances in the subnet.
Allows you to connect one VPC with another via a direct network route using private IP addresses. So I can have an instance on one subnet inside a different VPC that could communicate to another instance inside another subnet inside another VPC and that will do that over a private IP address.
Instances behave as if they were on the same private network when you peer VPCs.
You can peer VPC's with other AWS accounts as well as with other VPCs in the same account. So you can have a completely separate AWS account with a completely separate VPC and you are able to peer directly to that VPC in that other AWS account as well.
VPC peering connection allows you to route traffic between two VPCs using private IPv4 addresses or IPv6 addresses.
The VPCs can be in different Regions (a.k.a. inter-region VPC peering connection).
Peering is in a star configuration: i.e. 1 central VPC peers with 4 others. NO TRANSITIVE PEERING! It means if we have the structure as below:
Invalid VPC Peering connection configurations:
Overlapping CIDR blocks
Transitive Peering
Edge to edge routing through a gateway or private connection
You must be able to deploy a VPC on your own before you go to the exam.
Think of a VPC as a logical datacenter in AWS.
Consists of IGWs (Or virtual private gateways), route tables, network access control lists, subnets, and security groups.
1 Subnet = 1 Availability Zone (usually).
Few important points about VPC:
When you create a VPC, it spans all the AZs in the Region.
After creating a VPC, you can add one or more subnets in each AZ.
Security groups are stateful; Network access control lists are stateless. So if I was to open port 80 of my security group, automatically I can both send and receive port 80. I don't have to open up port 80 on my inbound rule list as well as my outbound rule list. With network access control lists, I have to open both inbound and outbound ports.
NO transitive peering.
The instance in VPC B can communicate with the instance in VPC C only if we directly peer VPC B with VPC C, otherwise they cannot communicate with each other.