Skip to main content
  1. 🔰Posts/
  2. 🗂️My Trainings/
  3. AWS Trainings and Certifications/
  4. 🏅AWS Certified Cloud Practitioner/

VPC

📚 Part 18 of 25: "AWS Cloud Practitioner" series.

·1681 words·8 mins

VPC - Virtual Private Cloud #

Amazon Virtual Private Cloud (VPC) enables you to provision logically isolated section of the AWS Cloud where you can launch AWS resources in a virtual network that you defined.

VPC components #

Virtual Private Cloud (VPC)A logically isolated virtual network in the AWS cloud
SubnetA segment of a VPC’s IP address range where you can place groups of isolated resources
Internet Gateway / Egress-only Internet GatewayThe Amazon VPC side of a connection to the public internet for IPv4/IPv6
RouterRouters interconnect subnets and direct traffic between internet gateways, virtual private gateways, NAT gateways and subnets
Peering ConnectionDirect connection between two VPC’s
VPC EndpointsPrivate Connection to public AWS services
NAT InstanceEnables Internet access for EC2 instances in private subnets (managed by you)
NAT GatewayEnables Internet access for EC2 instances in private subnets (managed by AWS)
Virtual Private GatewayThe Amazon VPC side of a Virtual Private Network (VPN) connection
Customer GatewayCustomer side of a VPN connection
Direct ConnectHigh Speed, high bandwidth, private network connection from customer to AWS
Security GroupInstance-level firewall
Network ACLSubnet-level firewall


VPC Rules and Guidance #

  • CIDR block size can be between /16 and /28
  • The CIDR block must not overlap with any existing CIDR block that’s associated with the VPC
  • You cannot increase or decrease the size of an existing CIDR block
  • The first four and last IP address are not available for use
  • AWS recommend you use CIDR blocks from the RFC 1918 ranges:
RFC 1918 NameIP Address RangeCIDR BlockClassful Description
10.0.0.010.0.0.0 – 10.255.255.25510.0.0.0/8Single Class A network
172.16.0.0172.16.0.0 – 172.31.255.255172.16.0.0/1216 contiguous Class B networks
192.168.0.0192.168.0.0 – 192.168.255.255192.168.0.0/16256 contiguous Class C networks

Purpose and Benefits #

  • Network Address Translation (NAT): Private IP addresses allow multiple devices on a local network to share a single public IP address through NAT.
  • Security: Using private addresses enhances security by making it difficult for external hosts to initiate connections to internal systems.
  • No Registration Required: Organizations can use these addresses without needing approval from Internet registries, simplifying network setup.

IP Addresses in AWS #

  • IPv4 (4.3 Billion Addresses)

    • Public IPv4 - can be used on the Internet
      • EC2 instance gets a new public IP address every time it’s started
    • Private IPv4 - can be used on private networks (LAN) such as internal AWS networking
      • Private IPv4 is fixed for EC2 instances even after stopping / starting
  • Elastic IP - allows to attach a fixed public IPv4 address to an EC2 instance

  • Note: Every public IPv4 address on AWS will be charged $0.005 per hour (including Elastic IP)

  • IPv6 - Number of addresses: 3.4 x 10^38

    • Every IP address is public in AWS (no private range) (??)
    • Free

VPC and Subnets Primer #

VPC - Virtual Private Cloud - private network to deploy resources (regional resource)

  • Subnets allow to partition the network inside of VPC (Availability Zone Resource)
  • A public subnet is a subnet that is accessible from the internet
  • A private subnet is a subnet that is not accessible from the internet
  • To define access to the internet and between subnets, we use Route Tables

Internet Gateway & NAT Gateways #

  • Internet Gateways help our VPC instances connecting with the internet

    • Public Subnets will have a route to the internet gateway
  • NAT Gateways (AWS Managed) & NAT Instances (self managed) allow instances in Private Subnets to access the internet while remaining private

Internet Gateway & NAT Gateways.

VPC > Subnets

EC2 Instance created in a Public Subnet will have Public IPv4 address associated. All Public Subnets have Internet Gateway (IGW) associated with them.

VPC > Virtual Private Cloud > Subnets > subnet-ID > Route table

All traffic coming to 172.31.0.0/16 will be considered local. Traffic to / from anywhere will go through an associated Internet Gateway.

Creating Private Subnet #

# For Private Subnet we don't associate it with any Internet Gateway. Traffic OUT goes via the NAT Gateway.

VPC > Virtual Private Cloud > Subnets > Create subnet

Security Groups & Network ACL #

Security Groups #

  • A firewall that controls traffic to and from an EC2 Instance
  • Can only have allow rules
  • Rules include IP addresses and other security groups

NACL (Network ACL) #

  • A firewall that controls traffic to and from a SUBNET
  • Can have allow and deny rules
  • Are attached at the Subnet level
  • Rules only include IP addresses

More: AWS Network Firewall that protects entire VPC.

VPC > Security > Security Groups

VPC > Security > Network ACLs
Security GroupNetwork ACL
Operates at the instance levelOperates at the subnet level
Supports ALLOW rules ONLYSupports ALLOW and DENY rules
Is stateful (return traffic is automatically allowed, regardless of any rules)Is stateless (return traffic must be explicitly allowed by rules)
All rules are evaluated before deciding whether to allow the trafficRules are processed in a number order when deciding to allow the traffic
Applies to an instance only if someone specified the Security Group when launching the instance (or associates it with the instance later on)Automatically applies to all instances in the subnets to which Network ACL is associated with
More info: https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Security.html

Default ACLs associated with the Default Subnets allow all traffic IN and OUT.

VPC Flow Logs #

Helps to monitor and troubleshoot connectivity issues #

  • Capture information about IP traffic going into your interfaces

    • VPC Flow Logs
    • Subnet Flow Logs
    • Elastic Network Interface Flow Logs
  • Helps to monitor and troubleshoot connectivity issues

    • Subnets to internet
    • Subnets to subnets
    • Internet to subnets
  • Captures network information from AWS managed interfaces too:

VPC Flow Logs must first be created for each VPC #
VPC > Virtual Private Cloud > Your VPCs > Flow Logs > Create flow log

VPC Peering #

Connect to VPC privately using AWS Network and make them behave as if they were in the same network.

  • Must NOT have overlapping CIDR (IP address range)
  • VPC Peering connection is NOT transitive (must be established for each VPC that needs to communicate with one another)

VPC > Virtual Private Cloud > Your VPCs > Peering Connections > Create peering connection

VPC Endpoints #

Endpoints allow connecting to AWS Services using a private network instead of the public www network.

This gives enhanced security and lower latency to access AWS services.

  • VPC Endpoint Gateway - for Amazon S3 and DynamoDB only
  • VPC Endpoint Interface - most services (including S3 and DynamoDB)
Interface EndpointGateway Endpoint
WhatElastic Network Interface (ENI) with a private IPA gateway that is a target for a specific route
HowUses DNS entries to redirect trafficUses prefix lists in the route table to redirect traffic
Which servicesAPI Gateway, CloudFormation, CloudWatch, etc.S3, DynamoDB
SecuritySecurity GroupsVPC Endpoint Policies

Most secure and scalable way to expose a service to 1000s of VPCs. Using VPC Peering (see above) is not practical because of the management overhead.

  • Does not require VPC peering, internet gateway, NAT, route tables…
  • Requires a Network Load Balancer (NLB) - Service VPC and Elastic Network Interface (ENI) - Customer VPC

AWS Private Link

Site to Site VPN & Direct Connect #

Site to Site VPN #

  • Connect to an on-premises VPN to AWS
  • The connection is automatically encrypted
  • Goes over the public internet (cheaper and slower than Direct Connect)

Site-to-Site VPN: - On-Premises - must use Customer Gateway (CGW) - AWS: must use a Virtual Private Gateway (VGW)

Site-to-Site VPN CloudHub #

Site-to-Site VPN CloudHub uses an Amazon VPC virtual private gateway with multiple customer gateways, each using unique BGP autonomous system numbers (ASNs).

The remote sites must not have overlapping IP ranges. Your gateways advertise the appropriate routes (BGP prefixes) over their VPN connections.

These routing advertisements are received and re-advertised to each BGP peer so that each site can send data to and receive data from the other sites.

Source: Site-to-Site VPN CloudHub

Direct Connect (DX) #

  • Establish a physical connection between on-premises and AWS
  • The connection is private, secure and fast
  • Goes over a private network (more expensive but faster than Site to Site VPN)
  • Takes at least a month to establish

AWS Client VPN #

Connect from your computer using OpenVPN to your private network in AWS and on-premises.

Allows connecting to your EC2 instances over a private IP (just as you were in the private VPC network).

Goes over the public Internet.

Transit Gateway #

Transit Gateway is used for having transitive peering between thousands of VPC and on-premises, hub-and-spoke (star) connection. #

Works with Direct Connect Gateway, VPN connections.

Summary #

  • VPC: Virtual Private Cloud
  • Subnets: Tied to and AZ, network partition of the VPC
  • Internet Gateway: at the VPC level, provide Internet Access
  • NAT Gateway / Instances: give internet access to private subnets
  • Security Groups: Stateful, operate at the EC2 instance level for ENI
  • NACL: Stateless, subnet rules for inbound and outbound
  • VPC Peering: Connect two VPC with non overlapping IP ranges, non-transitive (must be established for each VPC that needs to communicate with one another)
  • Elastic IP: Fixed public IPv4
  • VPC Endpoints: Provide private access to AWS Services within VPC
  • Private Link: Privately connect to a service in a 3rd party VPC
  • VPC Flow Logs: Network traffic logs
  • Site to Site VPN: VPN over public internet between on-premises DC and AWS
  • Site-to-Site VPN CloudHub
  • Client VPN: OpenVPN connection from your computer into your VPC
  • Direct Connect: Direct private connection to AWS
  • Transit Gateway: Connect thousands of VPC and on-premises networks together

» Sources « #

» References « #

» Disclaimer « #

This series draws heavily from Stephane Maarek’s Ultimate AWS Certified Cloud Practitioner course on Udemy.

His content was instrumental in helping me pass the certification.

About the instructor
🌐 Website📺 YouTube
💼 LinkedIn𝕏 x.com

ℹ️Shared for educational purposes only, no rights reserved.