Skip to Content
Cloud Engineering Academy
2. AWS Networking & Infrastructure

Amazon VPC fundamentals

Understand what a VPC is, what AWS puts in the default VPC, how VPC DNS works, and why banks delete default VPCs and turn on VPC Block Public Access.

beginner⏱ 1 h 🟢 FreeSAA-C03SOA-C03SCS-C03

Assumes: AWS CLI v2 · AWS SDK for .NET v4 (AWSSDK.EC2 4.1.4) · .NET 10 LTS · CDK v2 (Amazon.CDK.Lib 2.277.0) · Terraform AWS provider v6 · Region us-east-1. Verified against official sources on 2026-11-17.

Learning objectives

By the end of this lesson you can:

  • Explain what a VPC is, what lives at Region scope and what lives at Availability Zone scope.
  • List the parts of a VPC (CIDR blocks, subnets, implied router, route tables, gateways, DNS settings, network interfaces) and what each one does.
  • Describe the default VPC and explain why a bank removes it and blocks public access at account level.
  • Create a VPC with the console, CLI, CDK and Terraform, with DNS settings and mandatory tags.
  • Run a C# inventory tool that finds default VPCs and VPCs without Flow Logs in every Region.

Prerequisites

Why this matters in banking

Every new AWS account arrives with a default VPC in every Region. It has an internet gateway, a route to the internet and subnets that hand out public IP addresses automatically. A developer who launches a test database "just to try something" in that VPC can expose it to the internet in two clicks.

Bank security reviews treat this as a known finding. The standard response is: delete the default VPCs, stop them being recreated, turn on account-level blocks for internet access where workloads must never be public, and build every VPC deliberately from code. This lesson teaches the pieces you need to understand before you build your own.

The idea in plain language

A Virtual Private Cloud (VPC) is your own private network inside an AWS Region. You choose its address range, cut it into subnets, and decide what can enter and leave. Nothing gets in or out unless you add a door (a gateway) and a path to it (a route).

Analogy: a VPC is a bank branch building in one city (the Region). Each floor sits on a separate foundation — an Availability Zone — so a flood on one floor does not reach the others. Subnets are rooms on a floor. The building has a concierge desk on every floor (the implied router) that knows how to reach every room. There is no street entrance until you build one (an internet gateway), and even then a room only uses it if its corridor sign (route) points there.

Key terms:

TermPlain meaning
Region scopeThe VPC spans all AZs in a Region
AZ scopeA subnet lives in exactly one AZ
CIDR blockThe VPC's address range: one primary plus optional secondary ranges
Implied routerA built-in router at the VPC's base address + 1; you never see it, you configure it with route tables
ENIElastic Network Interface — a virtual network card with a private IP, security groups and a MAC address; instances, load balancers, Lambda functions and endpoints all use them
DHCP option setSettings handed to instances: domain name, DNS servers, NTP servers
Tenancydefault (shared hardware) or dedicated (single-tenant hardware, more expensive)

VPC DNS

Each VPC has an Amazon-provided DNS resolver (Route 53 Resolver) reachable at the VPC base address + 2 (for 10.20.0.0/16, that is 10.20.0.2) and at 169.254.169.253 from any subnet. Two VPC attributes control it:

  • enableDnsSupport — the resolver answers queries. Leave it on; private hosted zones and interface endpoints depend on it.
  • enableDnsHostnames — instances get DNS names such as ip-10-20-64-15.ec2.internal. Needed for private DNS on interface endpoints.

IPv6

You can add an Amazon-provided IPv6 /56 (or one from your own pool via IPAM). Subnets then get /64s. IPv6 addresses are globally routable, so outbound-only IPv6 needs an egress-only internet gateway — covered in route tables.

What problem Amazon VPC solves

Without a VPC, you could not isolate workloads from each other or from the internet, or connect privately to your data centres. A VPC gives you:

  • Isolation: your traffic is logically separated from other customers'.
  • Control: you decide routes, firewalls and gateways.
  • Private connectivity: to AWS services (endpoints), other VPCs (peering, Transit Gateway) and on-premises (VPN, Direct Connect).
  • Evidence: Flow Logs record every connection attempt.

Limits and sharp edges (checked 2026-11-17)

QuotaDefaultAdjustable
VPCs per Region5Yes (hundreds)
IPv4 CIDR blocks per VPC5Yes, up to 50
Subnets per VPC200Yes
Route tables per VPC200Yes
Network interfaces per Region5,000 per AZYes
Packets per second to the Amazon DNS resolver1,024 per ENINo
  • A VPC CIDR must be between /16 and /28. You cannot resize the primary CIDR later; you can only add secondary CIDRs.
  • A VPC never spans Regions. Multi-Region designs need two VPCs and something to connect them.
  • The 1,024 packets-per-second DNS limit per ENI surprises chatty microservices; cache DNS answers in .NET (the default SocketsHttpHandler connection pooling already helps).
  • Cost: the VPC itself, subnets, route tables, internet gateways, security groups and NACLs are free. Things you put in the VPC cost money (NAT gateways, endpoints, public IPv4 addresses at USD 0.005/hour each, load balancers).

The default VPC

ComponentDefault VPC settingWhy it is risky for a bank
CIDR172.31.0.0/16 in every Region and every accountOverlaps between accounts; collides with networks that use 172.16/12
SubnetsOne /20 per AZ, all publicNo private tier at all
Internet gatewayAttachedInternet path exists from day one
Main route table0.0.0.0/0 → igw-…Every subnet is public
Auto-assign public IPv4OnNew instances get internet addresses (and a USD 0.005/hour charge)
Default NACLAllows all in and outNo subnet guardrail
Default security groupAllows all traffic from members of itself, all outboundThings launched "with defaults" can talk to each other freely

Why banks delete it: it is internet-facing by design, it is identical in every account, and it is not built from code, so no review approved it. Deleting it is safe (nothing depends on it unless you put something there) and you can recreate it with aws ec2 create-default-vpc if you really need it.

VPC Block Public Access

VPC Block Public Access (BPA) is an account-level, per-Region switch that overrides routes and security groups:

  • Bidirectional — blocks all traffic through internet gateways and egress-only internet gateways in the Region.
  • Ingress-only — blocks inbound internet traffic; outbound through NAT gateways and egress-only internet gateways still works.
  • Exclusions — exempt a specific VPC or subnet (for example, the public subnets of a network-hub account), up to 50 per account per Region by default.

For a workload account that must never be reachable from the internet, BPA in bidirectional mode is a strong, simple control. You will meet it again in multi-account networking.

Microsoft / Azure comparison

You know (Microsoft/Azure)AWS equivalentWhat's different
Virtual Network (VNet)VPCBoth are regional; AWS subnets are bound to one AZ, Azure subnets span zones
VNet address spacePrimary + secondary CIDR blocksVPC limited to /16–/28 per block
Azure-provided DNS (168.63.129.16)Amazon DNS at VPC base + 2 and 169.254.169.253Toggled by enableDnsSupport
Default outbound access for VMsDefault VPC with an IGW and public IPsAWS custom VPCs have no internet path until you add one
Network interface (NIC)ENIENIs carry security groups directly
Azure Policy "deny public IP"VPC Block Public Access, SCPsBPA blocks at the gateway level, even if routes exist
Dedicated hostsDedicated tenancy / Dedicated HostsLicensing (for example Windows Server, SQL Server) is the usual reason

Architecture

Security-boundary view: the VPC boundary is a routing boundary, not a firewall. Inside it, every subnet can reach every other subnet through the implied router's local route; you restrict that with security groups and NACLs. At the edge, gateways (internet, NAT, VPN, endpoints) are the only doors, and BPA can lock the internet doors for the whole account.

Step-by-step implementation

Inspect the default VPC

In us-east-1, look at the default VPC's CIDR, subnets, route table and internet gateway (commands below). Write down what makes its subnets public.

Create a deliberate VPC

Create hl-m02-vpc with 10.20.0.0/16, DNS support and DNS hostnames on, and the four mandatory tags. It has no subnets and no gateways yet — it cannot reach anything.

Run the inventory tool

Run the C# program below to list every VPC in every enabled Region and flag default VPCs and VPCs without Flow Logs.

Delete the default VPC in us-east-1 (sandbox only)

Only in your sandbox account, and only if nothing runs in it: VPC → Your VPCs → select the default VPC → Actions → Delete VPC. The console deletes its subnets and gateway for you.

Optional: turn on VPC Block Public Access in ingress-only mode

This blocks inbound internet traffic in the Region. Remember to turn it off before the secure VPC lab, whose ALB needs inbound HTTP, or add an exclusion for that VPC.

AWS Console instructions

  • VPC → Your VPCs → Create VPC → VPC only. Name tag hl-m02-vpc, IPv4 CIDR manual input 10.20.0.0/16, no IPv6, tenancy Default. Add tags Project=cea-lab, Lab=m02-secure-vpc, Environment=learn, Owner=<you>. Create.
  • Select the VPC → Actions → Edit VPC settings → tick Enable DNS resolution and Enable DNS hostnames → Save.
  • VPC → Settings → Block public access shows the BPA mode for the Region ⚠ VERIFY exact menu label.
  • Default VPC: the Default VPC column says Yes. Actions → Delete VPC removes it and its dependencies.

AWS CLI

$p = "--profile", "learn-sandbox", "--region", "us-east-1"

# Show the default VPC (if it still exists)
aws ec2 describe-vpcs --filters Name=is-default,Values=true @p `
  --query "Vpcs[].[VpcId,CidrBlock]" --output table

# Create the lab VPC with tags in one call
$vpcId = aws ec2 create-vpc --cidr-block 10.20.0.0/16 @p `
  --tag-specifications "ResourceType=vpc,Tags=[{Key=Name,Value=hl-m02-vpc},{Key=Project,Value=cea-lab},{Key=Lab,Value=m02-secure-vpc},{Key=Environment,Value=learn},{Key=Owner,Value=alex}]" `
  --query Vpc.VpcId --output text

# DNS attributes must be set one per call
aws ec2 modify-vpc-attribute --vpc-id $vpcId --enable-dns-support '{"Value":true}' @p
aws ec2 modify-vpc-attribute --vpc-id $vpcId --enable-dns-hostnames '{"Value":true}' @p

# Confirm both attributes
aws ec2 describe-vpc-attribute --vpc-id $vpcId --attribute enableDnsHostnames @p

# Account-level VPC Block Public Access: view, then set ingress-only (optional)
aws ec2 describe-vpc-block-public-access-options @p
aws ec2 modify-vpc-block-public-access-options --internet-gateway-block-mode block-ingress @p

# Recreate a default VPC if you ever need one (sandbox only)
# aws ec2 create-default-vpc @p

@p is PowerShell "splatting": it passes the array as separate arguments, so you do not repeat the profile and Region on every line. In bash, use --profile learn-sandbox --region us-east-1 directly.

Infrastructure as Code

EmptyVpcStack.cs
using Amazon.CDK;
using Amazon.CDK.AWS.EC2;
using Constructs;

namespace Harbourline.Networking.Examples;

public sealed class EmptyVpcStack : Stack
{
    public EmptyVpcStack(Construct scope, string id, IStackProps? props = null) : base(scope, id, props)
    {
        // L1 construct: exactly one AWS::EC2::VPC, nothing else (the L2 Vpc construct adds subnets and gateways).
        var vpc = new CfnVPC(this, "Vpc", new CfnVPCProps
        {
            CidrBlock = "10.20.0.0/16",
            EnableDnsSupport = true,
            EnableDnsHostnames = true,
            InstanceTenancy = "default",
            Tags = [new CfnTag { Key = "Name", Value = "hl-m02-vpc" }],
        });

        Amazon.CDK.Tags.Of(this).Add("Project", "cea-lab");
        Amazon.CDK.Tags.Of(this).Add("Lab", "m02-secure-vpc");
        Amazon.CDK.Tags.Of(this).Add("Environment", "learn");

        _ = new CfnOutput(this, "VpcId", new CfnOutputProps { Value = vpc.Ref });
    }
}

Complete code

An inventory tool for the security team: every VPC in every enabled Region, flagging default VPCs and VPCs with no Flow Logs.

VpcInventory.csproj
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net10.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="AWSSDK.EC2" Version="4.1.4" />
    <PackageReference Include="AWSSDK.SSO" Version="4.1.0.1" />
    <PackageReference Include="AWSSDK.SSOOIDC" Version="4.1.0.2" />
  </ItemGroup>
</Project>
Program.cs
using Amazon;
using Amazon.EC2;
using Amazon.EC2.Model;

// Run with:  $env:AWS_PROFILE = "learn-sandbox"; dotnet run
var findings = 0;

using var global = new AmazonEC2Client(RegionEndpoint.USEast1);
var regions = await global.DescribeRegionsAsync(new DescribeRegionsRequest { AllRegions = false });

foreach (var region in regions.Regions ?? [])
{
    using var ec2 = new AmazonEC2Client(RegionEndpoint.GetBySystemName(region.RegionName));

    var vpcs = new List<Vpc>();
    var vpcPages = ec2.Paginators.DescribeVpcs(new DescribeVpcsRequest());
    await foreach (var vpc in vpcPages.Vpcs)
    {
        vpcs.Add(vpc);
    }

    if (vpcs.Count == 0)
    {
        continue;
    }

    var flowLogs = await ec2.DescribeFlowLogsAsync(new DescribeFlowLogsRequest
    {
        Filter = [new Filter { Name = "resource-id", Values = vpcs.Select(v => v.VpcId).ToList() }],
    });
    var withFlowLogs = (flowLogs.FlowLogs ?? []).Select(f => f.ResourceId).ToHashSet();

    foreach (var vpc in vpcs)
    {
        var name = vpc.Tags?.FirstOrDefault(t => t.Key == "Name")?.Value ?? "(no name)";
        var problems = new List<string>();
        if (vpc.IsDefault == true) problems.Add("DEFAULT VPC");
        if (!withFlowLogs.Contains(vpc.VpcId)) problems.Add("NO FLOW LOGS");

        findings += problems.Count;
        Console.WriteLine($"{region.RegionName,-15} {vpc.VpcId,-22} {vpc.CidrBlock,-16} {name,-20} {string.Join(", ", problems)}");
    }
}

Console.WriteLine(findings == 0 ? "No findings." : $"{findings} finding(s).");
return findings == 0 ? 0 : 1;

Code explained line by line

  1. AWSSDK.EC2 4.1.4 — the VPC APIs live in the EC2 service. AWSSDK.SSO and AWSSDK.SSOOIDC must be referenced so the SDK can use your IAM Identity Center profile at runtime.
  2. new AmazonEC2Client(RegionEndpoint.USEast1) — no keys in code; the SDK's credential chain reads AWS_PROFILE.
  3. DescribeRegionsAsync(... AllRegions = false) — only Regions enabled for the account; opt-in Regions you never enabled are skipped.
  4. regions.Regions ?? [] — in SDK v4, collection properties are null when the response has no items, so always guard them.
  5. ec2.Paginators.DescribeVpcs(...) — the paginator follows NextToken for you; await foreach streams results.
  6. DescribeFlowLogsAsync with a resource-id filter — one call per Region returns every flow log attached to these VPCs.
  7. vpc.IsDefault == true — IsDefault is a nullable bool? in v4, so compare explicitly.
  8. return findings == 0 ? 0 : 1; — a non-zero exit code lets a pipeline job fail when someone recreates a default VPC.

Security considerations

  • Build VPCs only from code (CDK, Terraform), reviewed in pull requests. The console is for learning and investigation.
  • Remove default VPCs in every Region of every workload account, and use an SCP to deny ec2:CreateDefaultVpc so they do not return ⚠ VERIFY that your organisation's SCP baseline does not already handle this.
  • Turn on VPC Block Public Access in accounts that must never be internet-facing; it holds even if someone adds an internet gateway route by mistake.
  • Keep enableDnsSupport on; turning it off breaks private hosted zones and endpoints in ways that look like outages.

⚠ Learning shortcut — not for production

In this lesson you delete the default VPC by hand in one Region of a sandbox account. In a bank, a central platform team removes default VPCs in all Regions of every new account automatically (for example with Control Tower account customisations or an account-vending pipeline), and an SCP stops them being recreated. Detection (the inventory tool above, or AWS Config) runs continuously.

Banking use case

Harbourline's account-vending pipeline creates a new workload account for the Payments team. Before the account is handed over, an automation step deletes the default VPC in every enabled Region, sets VPC Block Public Access to bidirectional with no exclusions, and shares subnets from the central network account (see multi-account networking). The payments team never sees an internet gateway; if a future project needs public ingress, it goes through the network team's shared ingress design and a security review.

Common mistakes

  • Using the default VPC for "just a quick test" → resources get public IPs → always deploy into a deliberate VPC.
  • Choosing a VPC CIDR without checking the IP plan → overlaps with on-premises ranges are permanent → follow CIDR planning.
  • Turning off enableDnsSupport → interface endpoints and private zones stop resolving → leave it on.
  • Assuming a VPC is a firewall → all subnets can talk through the local route → use security groups and NACLs.
  • Forgetting VPC BPA is on → your ALB is unreachable and nothing in the route tables explains why → check the BPA setting and exclusions.

Troubleshooting

SymptomLikely causeFix
VpcLimitExceeded when creating a VPC5 VPCs per Region alreadyDelete unused VPCs or request a quota increase
Instances have no DNS namesenableDnsHostnames is offEnable it in Edit VPC settings
DependencyViolation on delete-vpcSubnets, gateways, ENIs or endpoints still existDelete dependants first; check ENIs left by Lambda or load balancers
Internet traffic blocked though routes and SGs look rightVPC Block Public Access is onaws ec2 describe-vpc-block-public-access-options
Inventory tool throws UnauthorizedOperationMissing ec2:DescribeVpcs/DescribeFlowLogs/DescribeRegionsUse a read-only permission set (ViewOnlyAccess covers these)

Cost and cleanup

Cost: USD 0. VPCs, DNS settings and BPA are free; describe calls are free.

# Delete the empty lab VPC (no subnets or gateways yet)
aws ec2 delete-vpc --vpc-id $vpcId --profile learn-sandbox --region us-east-1

# If you turned on BPA and want it off again
aws ec2 modify-vpc-block-public-access-options --internet-gateway-block-mode off --profile learn-sandbox --region us-east-1

# Nothing tagged for the labs should remain
aws resourcegroupstaggingapi get-resources --tag-filters Key=Project,Values=cea-lab `
  --region us-east-1 --profile learn-sandbox --query "ResourceTagMappingList[].ResourceARN"

Exercises

  • 🟢 Guided: Create hl-m02-vpc with the CLI, enable both DNS attributes, run the inventory tool and confirm it reports NO FLOW LOGS for the new VPC. Delete the VPC.
  • 🟡 Challenge: Extend the inventory tool to report, for each VPC, whether an internet gateway is attached and whether any subnet has MapPublicIpOnLaunch = true.
  • 🔴 Live problem: A colleague says "I deleted the default VPC in us-east-1 and now my old CloudFormation template that launches an EC2 instance fails with VPCIdNotSpecified". Explain what happened and what the right fix is (not "recreate the default VPC").

Assignment

Add tools/vpc-inventory/ to your learning repository with the program, a README explaining each finding, and a sample output from your sandbox account (with account IDs redacted).

Solutions

Knowledge check

Interview questions

  • "What's in a default VPC and would you use it?" — 172.31.0.0/16, a public /20 per AZ, an attached IGW, a default route to it, auto-assigned public IPs. Not for workloads: I'd delete it and deploy deliberate VPCs from IaC.
  • "How would you guarantee no workload account is internet-reachable?" — Layered: no IGWs (SCP), VPC Block Public Access, shared subnets owned by a network account, Config rules for detection, and Network Access Analyzer scopes.
  • "Why might DNS queries fail under load in a VPC?" — The per-ENI limit of 1,024 packets per second to the Amazon resolver; cache DNS and reuse connections.

Certification practice

Completion checklist

  • I can list what lives at Region scope and what lives at AZ scope
  • I inspected the default VPC and can say why it is risky
  • I created and deleted hl-m02-vpc with DNS settings and tags
  • I ran the inventory tool
  • I checked my VPC Block Public Access setting and left it in a known state

Key takeaways

  • A VPC is a regional private network; subnets are zonal.
  • Nothing enters or leaves a custom VPC until you add a gateway and a route.
  • The default VPC is public by design — banks delete it and prevent its return.
  • VPC Block Public Access is an account-level override that beats routes and security groups.
  • Leave VPC DNS support on; private DNS features depend on it.

Further reading

Independent learning resource — not affiliated with, endorsed or sponsored by Amazon Web Services. AWS and related marks are trademarks of Amazon.com, Inc. or its affiliates. All banking data in examples is fictional. Sample architectures are for learning and are not automatically compliant with GDPR, PCI DSS or any banking regulation.

On this page