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

Lab: prove it's private — a database the internet cannot reach

Deploy a three-tier VPC with an isolated PostgreSQL database, then prove it is unreachable from the internet with Reachability Analyzer, VPC Flow Logs and a tested C# evidence checker — and tear it all down within the hour.

intermediate⏱ 2 h 🟡 Low costSAA-C03SOA-C03SCS-C03

Assumes: .NET 10 LTS · CDK v2 (Amazon.CDK.Lib 2.277.0, Cdklabs.CdkNag 3.0.2) · Terraform 1.14 / AWS provider v6 · AWS CLI v2 · PowerShell 5.1+ · Region us-east-1. Verified against official sources on 2026-11-18.

This is the Module 2 exercise. You build the secure VPC the whole module has been describing, put a real database in an isolated subnet, and then do what an architecture review at a bank actually asks for: produce evidence that nothing on the internet can reach it.

Learning objectives

By the end of this lab you can:

  • Deploy a three-tier VPC (public, app, isolated data) from CDK in C# or from Terraform, and explain every route, security group and network ACL rule in it.
  • Use VPC Reachability Analyzer to show that no path exists from the Internet Gateway to the database's network interface — and that a path does exist from the app tier, so the test is not trivially "no".
  • Query VPC Flow Logs with CloudWatch Logs Insights for accepted and rejected connection attempts on the database port.
  • Run a tested C# checker over the exported records and get a yes/no verdict you can attach to a change ticket.
  • Write the security claims as unit tests over the synthesized template, so they are checked on every build without an AWS account.
  • Tear everything down and prove nothing tagged for the lab is left.

Prerequisites

  • Amazon VPC fundamentals and CIDR planning — the address plan used here.
  • VPC Flow Logs and Reachability Analyzer — the two evidence tools, in depth.
  • The rest of the module's lessons on subnets, route tables, security groups and load balancing (see the module overview).
  • Tools: .NET 10 SDK (or Docker), Node.js 20+ and the CDK CLI (npm install -g aws-cdk) or Terraform 1.10+, AWS CLI v2 signed in with aws sso login --profile learn-sandbox, PowerShell.
  • Lab code: labs/m02-secure-vpc in this repository — the README there is the short version of this page.

VPC Block Public Access

If you switched on VPC Block Public Access in the VPC fundamentals lesson, the ALB in this lab cannot receive traffic. Check with aws ec2 describe-vpc-block-public-access-options --profile learn-sandbox and either turn it off for the lab or add an exclusion for the lab VPC. Turn it back on afterwards.

Why this matters in banking

Every bank architecture review has a version of the same question: "Show me that the customer database cannot be reached from the internet." An answer of "the security group doesn't allow it" is an opinion. Auditors, the second line of defence and penetration testers want evidence: something reproducible, dated and attributable, that would have caught the mistake if it had been made.

There are three classic ways this goes wrong in real estates:

  1. A developer ticks Publicly accessible on an RDS instance "just to test from my laptop" and forgets to untick it.
  2. Someone adds a 0.0.0.0/0 route to a NAT gateway or Internet Gateway on the wrong route table — the data tier now has a path out, and sometimes a path in.
  3. A security group rule is widened to 10.0.0.0/8 "temporarily", which quietly includes every on-premises network and every other VPC.

The lab gives you two kinds of evidence. Reachability Analyzer reasons over the configuration and says whether a path could exist — it catches (1) and (2) before any traffic flows. Flow Logs record what actually happened — they show that real connection attempts from the wrong place were rejected. Together with the build-time tests, you have the "design, configuration, runtime" triangle that security reviewers like to see.

The idea in plain language

You will build a small branch office for Harbourline Bank:

  • The lobby (public subnets) has the front desk — an Application Load Balancer — that anyone on the street can talk to. There is also a "probe" machine in the lobby that plays a compromised web server and rattles the vault door every minute.
  • The back office (app subnets) holds the application. Only the front desk may pass work to it.
  • The vault (isolated data subnets) holds the database. Only the back office may open the vault door, and the vault has no door to the street at all.

Then you hire two inspectors. One reads the building plans and confirms there is no corridor from the street to the vault (Reachability Analyzer). The other reviews the CCTV footage and confirms that every attempt to open the vault from the lobby was refused, while the back office got in as expected (Flow Logs).

Analogy: a fire-safety inspector checks the plans and the alarm log. Plans alone miss the door someone propped open last Tuesday; the log alone cannot tell you about a door nobody has tried yet.

What the AWS services do here

ServiceRole in the labHonest limits
Amazon VPC, subnets, route tables, Internet GatewayThe network; the data tier's route table has only the local routeA route table alone does not stop traffic within the VPC
Security groupsStateful allow-lists chained ALB → app → DB by group referenceNo deny rules; easy to widen by accident
Network ACL (data tier)Stateless backstop: only 5432 from the app subnets in, ephemeral ports backMust allow return traffic explicitly; rule order matters
RDS for PostgreSQLThe protected asset, PubliclyAccessible=false, encrypted, password in Secrets ManagerSingle-AZ here to keep it cheap
VPC Flow LogsRecords ACCEPT/REJECT for every flow on every ENI, 1-minute aggregationNot a packet capture; some traffic (Amazon DNS, metadata) is never logged
VPC Reachability AnalyzerProves whether a path exists between two resources from configuration aloneUSD 0.10 per analysis; analyses one source–destination pair at a time
CloudWatch Logs InsightsAd-hoc queries over the flow-log groupCharged per GB scanned

Microsoft / Azure comparison

You know (Microsoft/Azure)AWS equivalent in this labWhat's different
VNet with subnets, NSGs and UDRsVPC, subnets, security groups + NACLs, route tablesAWS splits NSG behaviour into stateful SGs (on ENIs) and stateless NACLs (on subnets)
Application security groups (ASGs)Security-group referencingAWS SG rules can name another SG as source; no separate ASG object
Azure SQL / PostgreSQL Flexible Server with public access disabledRDS with PubliclyAccessible=false in isolated subnetsRDS lives inside your VPC subnets; no "VNet integration" switch needed
NSG/VNet flow logs + Traffic AnalyticsVPC Flow Logs + Logs Insights or AthenaRecords land in CloudWatch Logs or S3; you write the queries
Network Watcher IP flow verify / Connection troubleshootReachability AnalyzerAnalyzer is configuration-based (sends no packets) and returns explanation codes for every blocking component
ARM/Bicep what-if + Pester testsCDK synth + xUnit assertions over the template, cdk-nagTests run locally against the synthesized CloudFormation JSON

Architecture

Security-boundary view

Three independent controls stand between the internet and the database: no public address (the IGW has nothing to translate to), no route from the data subnets to any gateway, and two layers of filtering (the NACL and the database security group). The lab proves each of them.

Step-by-step implementation

1. Get the code and run the free tests

cd labs/m02-secure-vpc
dotnet test --solution SecureVpc.slnx

Expected: Test run summary: Passed! across three test projects (98 tests). No AWS account is used. The CDK tests need Node.js because CDK for .NET runs the construct library in a Node process; without Node they are skipped, not failed.

No local .NET SDK? Use Docker (the SDK image has no Node, so the command installs it first):

MSYS_NO_PATHCONV=1 docker run --rm --memory 3g -v "$PWD:/src" -w /src mcr.microsoft.com/dotnet/sdk:10.0 \
  sh -c "apt-get update -qq && apt-get install -y -qq nodejs >/dev/null; dotnet test --solution SecureVpc.slnx; find . -type d \( -name bin -o -name obj \) -prune -exec rm -rf {} +"

2. Read the security claims before you deploy

Open tests/Harbourline.Networking.SecureVpc.Cdk.Tests/DatabaseIsolationTests.cs. Each test is one sentence a reviewer would say out loud:

TestClaim
Every_ingress_rule_on_the_db_security_group_comes_from_the_app_security_group_on_5432Only the app tier may connect, only on 5432, and never by IP range
No_ingress_rule_anywhere_in_the_stack_opens_the_database_port_to_the_worldThe only world-open port in the whole stack is the ALB's 80
Database_is_private_encrypted_and_in_the_data_subnetsPubliclyAccessible=false, StorageEncrypted=true, subnet group = exactly the data subnets
Data_tier_route_tables_have_no_default_route (with and without NAT)No AWS::EC2::Route at all in the data route tables — only the implicit local
Data_tier_nacl_only_admits_postgres_from_the_app_subnetsThe NACL allows exactly two ingress entries: 5432 from each app /20

These tests are the design evidence. If a future change breaks a claim, the pipeline fails before anything reaches AWS.

3. Deploy (start the one-hour clock)

cd labs/m02-secure-vpc/infra/cdk
# Once per account/Region, if you have never used CDK there:
cdk bootstrap aws://<account-id>/us-east-1 --profile learn-sandbox
cdk deploy --profile learn-sandbox -c owner=<your-name>

cdk-nag runs during synthesis. Every rule the stack deliberately breaks is acknowledged in code with a reason (look for AddNagSuppressions in SecureVpcStack.cs); any new finding stops the deployment.

RDS takes about 10 minutes. When it finishes, note the outputs: VpcId, InternetGatewayId, DbSecurityGroupId, DbEndpoint, AppInstanceId, ProbeInstanceId, AlbDnsName, FlowLogGroupName.

4. Check the application works

Open http://<AlbDnsName>/ in a browser. You should see Harbourline demo app (m02-secure-vpc). That page is served by the app instance in a private subnet — the ALB is the only public thing in the design.

aws elbv2 describe-target-health --profile learn-sandbox `
  --target-group-arn (aws elbv2 describe-target-groups --names hl-m02-app-tg --profile learn-sandbox --query "TargetGroups[0].TargetGroupArn" --output text)

With CDK the target group has a generated name; use Console → EC2 → Target groups and filter by the Lab tag instead. Target state should be healthy.

5. Inspect the controls yourself

Before running any automation, look at the four things that make the database private:

$p = '--profile', 'learn-sandbox'
$vpc = '<VpcId>'

# a) Route tables: the data tier has only the local route
aws ec2 describe-route-tables @p --filters "Name=vpc-id,Values=$vpc" `
  --query "RouteTables[].{Name:Tags[?Key=='Name']|[0].Value, Routes:Routes[].[DestinationCidrBlock,GatewayId,NatGatewayId,DestinationPrefixListId]}"

# b) The database SG: one rule, source = the app SG
aws ec2 describe-security-group-rules @p --filters "Name=group-id,Values=<DbSecurityGroupId>" `
  --query "SecurityGroupRules[].{In:!IsEgress,Port:FromPort,FromSg:ReferencedGroupInfo.GroupId,Cidr:CidrIpv4}"

# c) The data-tier NACL entries
aws ec2 describe-network-acls @p --filters "Name=tag:Name,Values=hl-m02-data-nacl" `
  --query "NetworkAcls[0].Entries[].[RuleNumber,Egress,RuleAction,CidrBlock,PortRange.From,PortRange.To]" --output table

# d) The RDS instance is not publicly accessible
aws rds describe-db-instances @p --db-instance-identifier hl-m02-db `
  --query "DBInstances[0].{Public:PubliclyAccessible,Encrypted:StorageEncrypted,Subnets:DBSubnetGroup.Subnets[].SubnetIdentifier}"

What to expect: the data route table shows only 10.20.0.0/16 local; the DB SG has exactly one ingress rule with FromSg set and Cidr empty; the NACL has rules 100 and 110 allowing 5432 from 10.20.64.0/20 and 10.20.80.0/20, plus the default * deny; Public is false.

6. Wait for evidence, then run the proof

The probe and the app each try the database once a minute. Give them 10 minutes so Flow Logs have a few aggregation intervals to deliver. Then:

cd labs/m02-secure-vpc
./scripts/prove-isolation.ps1            # -Tool terraform if you deployed with Terraform

The script does five things (all read-only on your VPC):

  1. Reads the stack outputs.
  2. Finds the database ENI through its security group and checks it has no public IP.
  3. Runs three Reachability Analyzer analyses on TCP 5432: IGW → DB (expect not reachable), probe → DB (expect not reachable), app → DB (expect reachable).
  4. Runs a Logs Insights query counting flows to port 5432 by source and action.
  5. Exports the raw records to evidence/flows.txt and runs the C# FlowLogCheck tool, which returns exit code 0 for "isolated" and 3 for "violation".

It then deletes the Reachability Analyzer paths it created.

7. Read the evidence

Expected console output (IDs and counts differ):

== 2. Finding the database network interface
   eni-0a1b2c3d4e5f60718 10.20.135.22 (subnet subnet-0123...)
   OK: no public IP on the database ENI
== 3. Reachability Analyzer (3 analyses, USD 0.10 each)
   PASS igw-to-db    path found = False IGW_PRIVATE_IP_ASSOCIATION_FOR_INGRESS
   PASS probe-to-db  path found = False SUBNET_ACL_RESTRICTION, ENI_SG_RULES_MISMATCH
   PASS app-to-db    path found = True
== 4. Logs Insights: REJECTs to port 5432 in the last 60 minutes
srcAddr      action flows
-------      ------ -----
10.20.70.14  ACCEPT    14
10.20.9.201  REJECT    14
== 5. Exporting raw flow records and running the C# checker
Records parsed: 31 (skipped 0 lines that are not default-format records)
Protected range 10.20.128.0/18 port 5432; allowed sources: 10.20.64.0/18
ACCEPT from allowed sources : 14
REJECT (blocked attempts)   : 14
  rejected from 10.20.9.201     x14
VERDICT: ISOLATED - no accepted connection from outside the allowed sources.
== RESULT: the database is private. Evidence saved in ./evidence/

The explanation codes are the interesting part. IGW_PRIVATE_IP_ASSOCIATION_FOR_INGRESS means the Internet Gateway refuses inbound traffic whose destination is not a public IP mapped to an ENI — the database has none, so the internet has nothing to address. For the probe, the analysis names both the data-subnet NACL and the database security group: two independent controls, each sufficient on its own. The exact codes can vary with your configuration ⚠ VERIFY against your own JSON in evidence/.

Open evidence/reachability-hl-m02-igw-to-db.json and find the Explanations array: each entry names the component (Component.Id), the code, and sometimes the route table or rule involved. This JSON is what you would attach to a change ticket.

8. Break it on purpose (optional, two minutes)

Prove the tests can fail. Add a rule that lets the probe's security group reach the database:

aws ec2 authorize-security-group-ingress --profile learn-sandbox --group-id <DbSecurityGroupId> `
  --ip-permissions "IpProtocol=tcp,FromPort=5432,ToPort=5432,UserIdGroupPairs=[{GroupId=<ProbeSecurityGroupId>,Description=deliberate-mistake}]"

Run the script again with -SkipReachability after two minutes: the flow records still show REJECT, because the NACL blocks the probe's subnet even though the SG now allows it. That is defence in depth working. Now run the full script: probe-to-db still fails on SUBNET_ACL_RESTRICTION only — the SG explanation has gone. Remove the rule:

aws ec2 revoke-security-group-ingress --profile learn-sandbox --group-id <DbSecurityGroupId> `
  --ip-permissions "IpProtocol=tcp,FromPort=5432,ToPort=5432,UserIdGroupPairs=[{GroupId=<ProbeSecurityGroupId>}]"

With CDK, cdk diff now shows nothing (the change was out-of-band), but drift detection in CloudFormation would have flagged it: Console → CloudFormation → hl-m02-secure-vpc → Stack actions → Detect drift.

9. Tear down and verify

Go to Cost and cleanup. Do not leave the stack running overnight.

AWS Console instructions

You can do the proof by hand in the console. It is slower but worth doing once.

Reachability Analyzer: Console → VPC → Reachability Analyzer → Create and analyze path. Source type Internet Gateways, source hl-m02 IGW; destination type Network Interfaces, destination the ENI whose description starts with RDSNetworkInterface; protocol TCP, destination port 5432. Name tag hl-m02-igw-to-db, add the lab tags. Create and analyze path. After about a minute the Reachability status shows Not reachable and the Explanations tab lists the blocking component.

Flow Logs: Console → CloudWatch → Logs → Logs Insights, select /hl/m02-secure-vpc/flow-logs, time range 1h, and run:

fields @timestamp, srcAddr, dstAddr, dstPort, action
| filter dstPort = 5432
| stats count(*) as flows by srcAddr, action
| sort flows desc

Delete the path afterwards: Reachability Analyzer → select path → Actions → Delete path.

AWS CLI

The script's core commands, so you can run them one at a time:

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

# Find the database ENI through its security group
$dbEni = aws ec2 describe-network-interfaces @p --filters "Name=group-id,Values=<DbSecurityGroupId>" `
  --query "NetworkInterfaces[0].NetworkInterfaceId" --output text

# Create a path from the Internet Gateway to the DB ENI on TCP 5432
$pathId = aws ec2 create-network-insights-path @p --source <InternetGatewayId> --destination $dbEni `
  --protocol tcp --destination-port 5432 `
  --tag-specifications "ResourceType=network-insights-path,Tags=[{Key=Project,Value=cea-lab},{Key=Lab,Value=m02-secure-vpc}]" `
  --query "NetworkInsightsPath.NetworkInsightsPathId" --output text

# Start an analysis (USD 0.10) and read the verdict
$analysisId = aws ec2 start-network-insights-analysis @p --network-insights-path-id $pathId `
  --query "NetworkInsightsAnalysis.NetworkInsightsAnalysisId" --output text
aws ec2 describe-network-insights-analyses @p --network-insights-analysis-ids $analysisId `
  --query "NetworkInsightsAnalyses[0].{Status:Status,PathFound:NetworkPathFound,Why:Explanations[].ExplanationCode}"

# Clean up the analysis and the path
aws ec2 delete-network-insights-analysis @p --network-insights-analysis-id $analysisId
aws ec2 delete-network-insights-path @p --network-insights-path-id $pathId

Run describe-network-insights-analyses again if Status is still running.

Infrastructure as Code

The full stack is in the lab folder. The two lines of code that matter most for "private" are the subnet type and the RDS flag:

infra/cdk/.../SecureVpcStack.cs (excerpt)
new SubnetConfiguration { Name = "data", SubnetType = SubnetType.PRIVATE_ISOLATED, CidrMask = SubnetPrefix },
// ...
Database = new DatabaseInstance(this, "Database", new DatabaseInstanceProps
{
    VpcSubnets = dataSubnets,
    SecurityGroups = [DatabaseSecurityGroup],
    PubliclyAccessible = false,
    StorageEncrypted = true,
    // ...
});
DatabaseSecurityGroup.AddIngressRule(AppSecurityGroup, Port.Tcp(DatabasePort), "PostgreSQL from the app tier only");

PRIVATE_ISOLATED in CDK means "a route table with no route to an Internet Gateway or NAT gateway". In Terraform you get the same thing by creating a route table and adding no aws_route resources to it.

Complete code

The evidence checker is a small, tested library in src/Harbourline.Networking.FlowLogs. The parser reads the default flow-log format:

src/Harbourline.Networking.FlowLogs/IsolationChecker.cs
using Harbourline.Networking.CidrPlanner;

namespace Harbourline.Networking.FlowLogs;

public sealed record IsolationReport(
    int AcceptedFromAllowed,
    int RejectedAttempts,
    IReadOnlyDictionary<string, int> RejectedBySource,
    IReadOnlyList<FlowLogRecord> Violations)
{
    public bool IsIsolated => Violations.Count == 0;
}

public static class IsolationChecker
{
    public static IsolationReport Check(
        IEnumerable<FlowLogRecord> records,
        Ipv4Cidr protectedRange,
        IReadOnlyCollection<Ipv4Cidr> allowedSources,
        int port)
    {
        ArgumentNullException.ThrowIfNull(records);
        ArgumentNullException.ThrowIfNull(allowedSources);

        var accepted = 0;
        var rejected = 0;
        var rejectedBySource = new SortedDictionary<string, int>(StringComparer.Ordinal);
        var violations = new List<FlowLogRecord>();

        foreach (var r in records)
        {
            if (!r.HasTraffic || r.DestinationPort != port || !IsIn(r.DestinationAddress, protectedRange))
            {
                continue;
            }

            if (r.Action == FlowAction.Reject)
            {
                rejected++;
                var key = r.SourceAddress ?? "(unknown)";
                rejectedBySource[key] = rejectedBySource.GetValueOrDefault(key) + 1;
            }
            else if (allowedSources.Any(a => IsIn(r.SourceAddress, a)))
            {
                accepted++;
            }
            else
            {
                violations.Add(r);
            }
        }

        return new IsolationReport(accepted, rejected, rejectedBySource, violations);
    }

    public static bool IsIn(string? address, Ipv4Cidr range) =>
        address is not null
        && Ipv4Cidr.TryParse(address + "/32", out var host)
        && range.Contains(host);
}

And one of its tests, using a fixture of fictional records shaped exactly like the lab's evidence:

tests/Harbourline.Networking.FlowLogs.Tests/IsolationCheckerTests.cs (excerpt)
[Fact]
public void Lab_evidence_is_isolated()
{
    var report = IsolationChecker.Check(Load("isolated.txt"), DataTier, AppTier, Postgres);

    Assert.True(report.IsIsolated);
    Assert.Equal(2, report.AcceptedFromAllowed);   // app -> db, two intervals
    Assert.Equal(4, report.RejectedAttempts);      // three from the probe + one from another public-tier address
    Assert.Equal(3, report.RejectedBySource["10.20.0.17"]);
}

Code explained line by line

  1. IsolationReport is a C# record: the four numbers a reviewer wants, plus IsIsolated, which is true only when the violation list is empty.
  2. Check(...) takes the records, the protected range (10.20.128.0/18, the data tier's aligned block from the IP plan), the allowed sources (10.20.64.0/18, the app tier) and the port.
  3. !r.HasTraffic skips NODATA and SKIPDATA marker records, which have - in every traffic field.
  4. r.DestinationPort != port skips everything not aimed at 5432. Crucially, this also skips the database's replies (source port 5432, destination an ephemeral port), so return traffic is never mistaken for an attempt.
  5. !IsIn(r.DestinationAddress, protectedRange) keeps only flows into the data tier.
  6. A REJECT is counted and grouped by source — the probe should dominate this list.
  7. An ACCEPT from an allowed source is the expected app-to-database traffic. Zero accepts would mean "no evidence yet", which the lab treats as inconclusive, not as success.
  8. Any other ACCEPT is a violation — the record is kept so you can see the time, ENI, source and port.
  9. IsIn turns an address into a /32 and asks the tested Ipv4Cidr type whether the range contains it. IPv6 addresses and - simply fail to parse and are treated as "not inside".

The FlowLogCheck console app wraps this: it reads --file, parses each line with FlowLogRecord.TryParse (which never throws, and skips lines in a custom format), prints the report and returns 0 for isolated, 3 for violation, 1 for bad input — exit codes a pipeline step can act on.

Security considerations

⚠ Learning shortcut — not for production

The ALB listens on plain HTTP 80. Production uses HTTPS 443 with an ACM certificate, an HTTP→HTTPS redirect, a modern TLS policy and AWS WAF in front.

⚠ Learning shortcut — not for production

RDS is single-AZ, deletion protection is off, there is no final snapshot and the master secret is not rotated, so the lab costs cents and tears down in one command. Production: Multi-AZ, deletion protection, snapshots retained under your records policy, rotation on, and IAM database authentication for applications.

⚠ Learning shortcut — not for production

Flow logs go to CloudWatch Logs with 7-day retention in the same account. A bank sends flow logs to a central, write-once log archive account (S3 with Object Lock, or a central log group) with retention set by its records policy, so a compromised workload account cannot delete its own evidence.

Things the lab already does properly, and why:

  • No SSH keys and no inbound admin ports. In a real estate you would reach instances through Systems Manager Session Manager with VPC interface endpoints, logged to CloudTrail.
  • IMDSv2 required on both instances, so an SSRF bug in the app cannot easily steal instance credentials.
  • Security groups reference groups, not CIDRs. A new app instance gets database access by joining the app SG; nobody edits an IP list.
  • The database SG has no egress rule. RDS does not need to start connections; the stateful SG still lets replies out.
  • Gateway endpoint policies allow only resources in the same account (aws:ResourceAccount), a first step towards a data perimeter.
  • Evidence handling. evidence/ contains account IDs and resource IDs. Keep it out of public repositories (it is in .gitignore).

None of this makes a workload compliant with GDPR, UK GDPR or PCI DSS. It produces the kind of evidence those assessments ask for; the decision belongs to your security, compliance and (for cards) QSA reviewers.

Banking use case

Harbourline's Payments Service is moving its PostgreSQL store to RDS. The change advisory board will not approve the production change without a network isolation evidence pack. The platform team reuses this lab's pattern:

  • The design tests run in the CI pipeline on every pull request that touches the network stack.
  • After each deployment to pre-prod and prod, a pipeline step runs the Reachability Analyzer checks (IGW → DB, on-premises VPN attachment → DB, shared-services VPC → DB) and stores the JSON in the evidence bucket in the log archive account.
  • A weekly job exports a day of flow records for the data subnets and runs FlowLogCheck; any exit code 3 opens a security incident ticket.
  • Network Access Analyzer (covered in VPC Flow Logs) adds a broader scope: "no path from any Internet Gateway to any ENI tagged DataClass=restricted", across all VPCs in the account.

The internal auditor's sample test becomes: "show me the last three evidence packs for the Payments database" — a few S3 objects, not a meeting.

Common mistakes

  • Running the proof straight after deploy. Flow logs deliver after the aggregation interval plus delivery delay. Wait 10 minutes, or you will see an empty Logs Insights result and wonder why.
  • Analysing the wrong destination. Reachability Analyzer needs the database's ENI (or instance ID for EC2). The RDS endpoint DNS name is not a valid destination.
  • Reading "not reachable" as proof without a positive control. A typo in a path (wrong port, wrong ENI) also returns "not reachable". The app-to-DB analysis must say reachable, or your negative results mean nothing.
  • Trusting flow logs for traffic they never record. Queries to the Amazon DNS resolver, instance metadata and Time Sync do not appear. Absence of a record is not proof of absence for those.
  • Forgetting the NACL return path. If you change the app subnets, the data NACL's outbound ephemeral rule must change too, or the app sees timeouts while the SG looks perfect.
  • Leaving the stack up. The ALB and RDS bill by the hour whether anyone uses them.

Troubleshooting

SymptomLikely causeFix
CDK tests skippedNode.js not on PATHInstall Node 20+, or use the Docker command
cdk deploy stops with a validation reportA cdk-nag rule fired that is not acknowledgedRead the report; fix the resource or add an Ack with a written reason
This stack uses assets, so the toolkit stack must be deployedAccount/Region not bootstrappedcdk bootstrap aws://<account>/us-east-1 --profile learn-sandbox
ALB URL times outVPC Block Public Access on, or target unhealthyTurn off BPA or add an exclusion; check target health
Target unhealthyUser data still running, or ALB→app rule missingWait 3 minutes; compare SG rules with security_groups.tf
app-to-db path found = FalseDB still creating, or a rule was editedWait for available; redeploy to restore the rules
igw-to-db path found = TrueDatabase made public or a route addedStop and investigate — this is the finding the lab exists to catch
VPC_BLOCK_PUBLIC_ACCESS_ENABLED in explanationsBPA is onExpected if you enabled BPA; note it as an extra control
Logs Insights shows no rowsToo early, or wrong log group / time rangeWait; check the FlowLogGroupName output and the time picker
FlowLogCheck parses 0 recordsRecords in a custom formatThe checker reads the default (version 2) format only
AccessDenied on CreateNetworkInsightsPathSandbox permission set lacks itAsk for ec2:*NetworkInsights* read/write in the learning permission set

Cost and cleanup

Cost while running (us-east-1, on-demand, checked 2026-11-18): RDS db.t4g.micro single-AZ with 20 GB gp3 ≈ USD 0.019/h; two Graviton instances ≈ USD 0.014/h; ALB hour plus minimum LCU ≈ USD 0.03/h; two public IPv4 addresses on the ALB at USD 0.005/h each = USD 0.01/h; Secrets Manager, flow-log ingestion and Logs Insights scans under USD 0.01. About USD 0.07 per hour, plus USD 0.10 per Reachability Analyzer analysis (the script runs three). One careful run, including the optional break-it step, costs well under USD 1. The RDS, EC2 and ALB rates are from the public price pages ⚠ VERIFY before relying on them; the Reachability Analyzer and public IPv4 rates were checked on the Amazon VPC pricing page.

Free alternative: run only Step 1 and Step 2. The synthesized-template tests and the C# checker over the fixtures demonstrate the same claims without deploying anything.

Teardown:

# 1. Destroy the stack (pick the tool you deployed with)
cd labs/m02-secure-vpc/infra/cdk;       cdk destroy --profile learn-sandbox
# cd labs/m02-secure-vpc/infra/terraform; terraform destroy -var owner=<your-name>

# 2. Any Reachability Analyzer paths left behind (only if you used -KeepPaths or the console)
aws ec2 describe-network-insights-paths --profile learn-sandbox `
  --filters Name=tag:Lab,Values=m02-secure-vpc --query "NetworkInsightsPaths[].NetworkInsightsPathId"

# 3. The flow-log group should be gone with the stack
aws logs describe-log-groups --profile learn-sandbox --log-group-name-prefix /hl/m02-secure-vpc

# 4. Nothing tagged for the lab remains (the tag index can lag a few minutes)
aws resourcegroupstaggingapi get-resources --region us-east-1 --profile learn-sandbox `
  --tag-filters Key=Project,Values=cea-lab Key=Lab,Values=m02-secure-vpc `
  --query "ResourceTagMappingList[].ResourceARN"

The RDS-generated secret is scheduled for deletion with a recovery window and can still appear in the tag check for a few days; secrets scheduled for deletion are not billed ⚠ VERIFY. If you switched VPC Block Public Access off for this lab, switch it back on.

Exercises

  • 🟢 Guided: Deploy, run the proof script, and save the three Reachability Analyzer JSON files and the checker output. Write two sentences per analysis explaining which component produced each explanation code.
  • 🟡 Challenge: Add a fourth Reachability Analyzer check to the script: from the ALB to the database on 5432. Predict the result and the explanation code before you run it. Then add an xUnit test to the CDK test project asserting that the ALB security group has no egress rule to the database security group.
  • 🔴 Live problem: A ticket arrives: "Pen-test finding PT-2026-114: database hl-m02-db responded on 5432 from 10.20.9.201 during the test window 14:00–14:20 UTC. Please confirm or refute." Using only Flow Logs and Reachability Analyzer evidence, write the response: what you queried, what you found, and your conclusion. (In the lab, 10.20.x.x is your probe.)

Assignment

Add an evidence/ summary to your portfolio repository (with account IDs redacted): a one-page ISOLATION-EVIDENCE.md containing the date, the three analysis verdicts with explanation codes, the Logs Insights table, the checker verdict, and a paragraph explaining why three independent controls protect the database. Link it from your CV as "network isolation evidence for a three-tier AWS design".

Solutions

Knowledge check

Interview questions

  • "How would you prove to an auditor that a database can't be reached from the internet?" — Three layers of evidence: build-time tests over the IaC template (no public flag, no default route, SG sources are other SGs), Reachability Analyzer from every internet-facing gateway to the database ENI with a positive control, and Flow Logs showing rejected attempts and only expected accepted sources. Stored centrally with dates.
  • "Security group or NACL — which would you rely on for the data tier?" — Security groups as the primary control because they are stateful and reference other groups; a simple NACL as a coarse backstop that a single SG mistake cannot bypass.
  • "What does Reachability Analyzer not tell you?" — Whether traffic actually flowed, anything about the application layer (TLS, credentials), and paths through unsupported components. It's configuration analysis, so pair it with Flow Logs.
  • "Why not just make the RDS instance 'not publicly accessible' and stop there?" — It is necessary but not sufficient: routes, SGs and peering/VPN paths from on-premises still matter. Defence in depth means each control is independently tested.

Certification practice

Completion checklist

  • All local tests passed (or I understood why CDK tests were skipped)
  • I deployed the stack and saw the demo page through the ALB
  • I inspected the data route table, DB security group, NACL and RDS flag myself
  • prove-isolation.ps1 reported PASS for all three analyses and VERDICT: ISOLATED
  • I can explain each explanation code in my evidence
  • I destroyed the stack and the tag check returned nothing billable

Key takeaways

  • "Private" is three properties: no public address, no route out, and filtering in two layers. Test each one.
  • Reachability Analyzer proves what could happen from configuration; Flow Logs prove what did happen. A positive control makes negative results trustworthy.
  • Security claims written as unit tests over the synthesized template run on every build, for free.
  • Evidence is a product: dated, reproducible, stored centrally and readable by someone who was not in the room.
  • Deploy, prove, destroy — this whole exercise costs well under a dollar if you finish within the hour.

Further reading

Next steps: go deeper on the evidence tools in VPC Flow Logs, then see how the same isolation scales across accounts in multi-account network architecture.

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