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.
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
- Networking refresher for developers
- Module 1: AWS fundamentals — Regions, AZs, the
learn-sandboxSSO profile. - Tools: AWS CLI v2, .NET 10 SDK; optionally the CDK CLI and Terraform.
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:
| Term | Plain meaning |
|---|---|
| Region scope | The VPC spans all AZs in a Region |
| AZ scope | A subnet lives in exactly one AZ |
| CIDR block | The VPC's address range: one primary plus optional secondary ranges |
| Implied router | A built-in router at the VPC's base address + 1; you never see it, you configure it with route tables |
| ENI | Elastic 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 set | Settings handed to instances: domain name, DNS servers, NTP servers |
| Tenancy | default (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 asip-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)
| Quota | Default | Adjustable |
|---|---|---|
| VPCs per Region | 5 | Yes (hundreds) |
| IPv4 CIDR blocks per VPC | 5 | Yes, up to 50 |
| Subnets per VPC | 200 | Yes |
| Route tables per VPC | 200 | Yes |
| Network interfaces per Region | 5,000 per AZ | Yes |
| Packets per second to the Amazon DNS resolver | 1,024 per ENI | No |
- 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
SocketsHttpHandlerconnection 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
| Component | Default VPC setting | Why it is risky for a bank |
|---|---|---|
| CIDR | 172.31.0.0/16 in every Region and every account | Overlaps between accounts; collides with networks that use 172.16/12 |
| Subnets | One /20 per AZ, all public | No private tier at all |
| Internet gateway | Attached | Internet path exists from day one |
| Main route table | 0.0.0.0/0 → igw-… | Every subnet is public |
| Auto-assign public IPv4 | On | New instances get internet addresses (and a USD 0.005/hour charge) |
| Default NACL | Allows all in and out | No subnet guardrail |
| Default security group | Allows all traffic from members of itself, all outbound | Things 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 equivalent | What's different |
|---|---|---|
| Virtual Network (VNet) | VPC | Both are regional; AWS subnets are bound to one AZ, Azure subnets span zones |
| VNet address space | Primary + secondary CIDR blocks | VPC limited to /16–/28 per block |
| Azure-provided DNS (168.63.129.16) | Amazon DNS at VPC base + 2 and 169.254.169.253 | Toggled by enableDnsSupport |
| Default outbound access for VMs | Default VPC with an IGW and public IPs | AWS custom VPCs have no internet path until you add one |
| Network interface (NIC) | ENI | ENIs carry security groups directly |
| Azure Policy "deny public IP" | VPC Block Public Access, SCPs | BPA blocks at the gateway level, even if routes exist |
| Dedicated hosts | Dedicated tenancy / Dedicated Hosts | Licensing (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 input10.20.0.0/16, no IPv6, tenancy Default. Add tagsProject=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
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.
<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>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
AWSSDK.EC24.1.4 — the VPC APIs live in the EC2 service.AWSSDK.SSOandAWSSDK.SSOOIDCmust be referenced so the SDK can use your IAM Identity Center profile at runtime.new AmazonEC2Client(RegionEndpoint.USEast1)— no keys in code; the SDK's credential chain readsAWS_PROFILE.DescribeRegionsAsync(... AllRegions = false)— only Regions enabled for the account; opt-in Regions you never enabled are skipped.regions.Regions ?? []— in SDK v4, collection properties arenullwhen the response has no items, so always guard them.ec2.Paginators.DescribeVpcs(...)— the paginator followsNextTokenfor you;await foreachstreams results.DescribeFlowLogsAsyncwith aresource-idfilter — one call per Region returns every flow log attached to these VPCs.vpc.IsDefault == true—IsDefaultis a nullablebool?in v4, so compare explicitly.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:CreateDefaultVpcso 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
enableDnsSupporton; 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
| Symptom | Likely cause | Fix |
|---|---|---|
VpcLimitExceeded when creating a VPC | 5 VPCs per Region already | Delete unused VPCs or request a quota increase |
| Instances have no DNS names | enableDnsHostnames is off | Enable it in Edit VPC settings |
DependencyViolation on delete-vpc | Subnets, gateways, ENIs or endpoints still exist | Delete dependants first; check ENIs left by Lambda or load balancers |
| Internet traffic blocked though routes and SGs look right | VPC Block Public Access is on | aws ec2 describe-vpc-block-public-access-options |
Inventory tool throws UnauthorizedOperation | Missing ec2:DescribeVpcs/DescribeFlowLogs/DescribeRegions | Use 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-vpcwith the CLI, enable both DNS attributes, run the inventory tool and confirm it reportsNO FLOW LOGSfor 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
The output lists us-east-1 vpc-… 10.20.0.0/16 hl-m02-vpc NO FLOW LOGS and, if you have not deleted it, the default VPC with DEFAULT VPC, NO FLOW LOGS. Why: the tool checks Flow Logs by resource ID; a new VPC has none until you create one, which you do in VPC Flow Logs.
Call DescribeInternetGatewaysAsync with filter attachment.vpc-id, and DescribeSubnetsAsync with filter vpc-id; flag subnet.MapPublicIpOnLaunch == true. Why: an attached IGW plus auto-assigned public IPs is the combination that silently makes new instances internet-reachable.
The template relied on the default VPC (it gave no subnet), so EC2 had nowhere to launch. The fix is to make the template take a SubnetId parameter (and security group) and deploy into a deliberate private subnet. Why: implicit dependencies on the default VPC are exactly what the bank's control is designed to remove.
Knowledge check
Answer: No and no. A VPC belongs to one Region; a subnet belongs to one AZ. Resilience comes from subnets in several AZs.
Answer: The Amazon-provided DNS resolver (Route 53 Resolver), reachable when enableDnsSupport is true. It is also reachable at 169.254.169.253.
Answer: An attached internet gateway, a main route table route 0.0.0.0/0 to it, and auto-assign public IPv4 on each subnet.
Answer: Outbound connections through NAT gateways and egress-only internet gateways (and their replies). It blocks inbound internet traffic.
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
A bank requires that no VPC in a workload account can receive traffic from the internet, even if an engineer adds an internet gateway and a route by mistake. Outbound internet access through NAT is still needed for patching. What is the simplest control?
A. A network ACL in every subnet denying 0.0.0.0/0 inbound B. VPC Block Public Access in ingress-only mode for the account and Region C. An AWS WAF web ACL on every load balancer D. A security group with no inbound rules attached to every instance
Answer: B. BPA ingress-only blocks inbound internet traffic at the gateway level while allowing NAT egress, regardless of routes. A must be maintained per subnet and would also break legitimate return traffic patterns. C only covers HTTP to load balancers. D depends on every engineer using the right group.
Instances in a new custom VPC have private IPs but no private DNS hostnames, and an interface endpoint's private DNS name does not resolve. What should the CloudOps engineer change?
A. Create a DHCP option set with a custom domain name
B. Enable enableDnsHostnames and enableDnsSupport on the VPC
C. Attach an internet gateway
D. Create a public hosted zone
Answer: B. Both attributes are needed for instance hostnames and for endpoint private DNS. A changes the domain suffix but does not enable resolution. C and D are unrelated to private DNS.
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-vpcwith 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.
Networking refresher for developers
Refresh IP addresses, CIDR notation, ports, DNS and TLS — the five ideas every AWS networking decision is built on — and test them from Windows and C#.
CIDR planning: an IP plan that never overlaps
Plan non-overlapping address ranges for dev, test, prod, two data centres and a partner, size subnets for AWS, and check the plan with a tested C# library (Lab 2.1).