Lesson 1 of 4 Networking and Content Delivery

Building Isolated Networks with Amazon VPC

This lesson explains how Amazon Virtual Private Cloud (Amazon VPC) lets you create a logically isolated network in AWS, controlling IP addresses, subnets, routing and security.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe the building blocks of a VPC, such as subnets, internet gateways and NAT gateways.
  • Identify the ways to connect networks, such as VPC peering and AWS Transit Gateway.
  • Distinguish security groups from network ACLs.
  • Describe what VPC Flow Logs record.

VPC building blocks

An Amazon VPC is your own private network in an AWS Region, with an IP address range that you choose. It is divided into subnets, each in one Availability Zone. A public subnet has a route to an internet gateway, which connects the VPC to the internet, so it suits resources that the internet must reach, such as web servers. A private subnet has no such route, so it suits resources that should not be reachable from the internet, such as databases.

Route tables decide where traffic from each subnet goes. A NAT gateway lets resources in a private subnet start outbound connections to the internet, for example to download updates, while still blocking connections from the internet to them. The following table summarises the components.

ComponentPurpose
VPCYour private network in a Region, with an IP range you choose
SubnetA section of the VPC in one Availability Zone
Public subnetHas a route to an internet gateway; for internet-facing resources such as web servers
Private subnetNo route to the internet gateway; for resources such as databases
Internet gatewayConnects the VPC to the internet
Route tableDecides where traffic goes
NAT gatewayLets private resources make outbound internet connections (e.g. for updates) without being reachable

The following diagram shows public and private subnets and their gateways.

The building blocks of an Amazon VPC. The VPC is a private network in a Region with an address range you choose, divided into subnets, each in one Availability Zone. A public subnet has a route to the internet gateway, so web servers there can be reached from the internet. A private subnet has no such route, so a database there cannot be reached; a NAT gateway lets private resources start outbound connections, such as downloading updates. Route tables decide where each subnet's traffic goes.
Only resources in the public subnet are reachable from the internet.
Match the pairs

VPC components

Exam skills 3.5.1

Match each VPC component with its purpose.

Log in to try this activity Interactive activities are free with an account.

Connecting networks

As an organisation grows, its networks need to be connected. VPC peering connects two VPCs directly, so their resources can communicate privately. AWS Transit Gateway acts as a central hub that connects many VPCs and on-premises networks, which is simpler than peering every pair of VPCs. VPC endpoints let resources in a VPC reach AWS services such as S3 privately, without going over the internet. The following table summarises the options.

OptionConnects
VPC peeringTwo VPCs
AWS Transit GatewayMany VPCs and on-premises networks through a central hub
VPC endpointsResources to AWS services such as S3 privately, without the internet
Scenario questions

Connecting networks

Exam skills 3.5.1 · 3.5.4

Choose how to connect networks and services.

Log in to try this activity Interactive activities are free with an account.

Security groups versus network ACLs

Security groups and network ACLs are both firewalls in a VPC, and their differences are often tested. A security group works at the level of an instance. It is stateful, so if a request is allowed in, the reply is allowed out automatically, and it contains only allow rules. A network ACL works at the level of a subnet. It is stateless, so replies must be allowed by their own rules, and it can contain deny rules, so it can block specific IP addresses. The following table summarises the differences.

Security group
LevelInstance
StateStateful: return traffic allowed automatically
RulesAllow only
Network ACL
LevelSubnet
StateStateless: return traffic must be allowed explicitly
RulesAllow and deny, so can block specific IPs

Visibility and protection

AWS provides services that give visibility into network traffic and protect it. The following list describes them.

  • VPC Flow Logs record IP traffic information for troubleshooting and security analysis.
  • Amazon Inspector finds unintended network exposure.
  • Security groups and network ACLs control which traffic may flow, as described above.
True or false

VPC visibility

Exam skills 3.5.2

Check the services that give visibility and protection in a VPC.

Log in to try this activity Interactive activities are free with an account.
Worked example

A two-tier network

A company builds a VPC for a web application with a database. The layout follows a common pattern:

ComponentConfiguration
Public subnets (one per AZ)Load balancer; route to the internet gateway
Private subnets (one per AZ)Web servers and the database; no direct route from the internet
NAT gatewayLets private servers download updates without being reachable from outside
Security group: load balancerAllows HTTPS (port 443) from anywhere
Security group: web serversAllows traffic only from the load balancer's security group
Security group: databaseAllows port 3306 only from the web servers' security group
Network ACLDenies a range of IP addresses known to attack the company

An attacker on the internet can reach only the load balancer. Even if they got past it, the database accepts connections only from the web servers. Security groups cannot deny, so blocking a specific IP range is done with the network ACL.

Check yourself

What is the difference between a security group and a network ACL?

Show answer

A security group works at the instance level, is stateful and has only allow rules. A network ACL works at the subnet level, is stateless and has allow and deny rules.

Exam Tips

Remember for the exam

  • A stateful instance-level firewall is a security group; a stateless subnet-level firewall is a network ACL.
  • To block a specific IP address, add a deny rule to a network ACL.
  • Internet access for a VPC requires an internet gateway.
  • For private resources that need outbound-only internet access, use a NAT gateway.
  • Each subnet lives in one Availability Zone.
  • To record information about network traffic, use VPC Flow Logs.