Skip to content

Lesson 263·M24 Cloud & AWS for AI

VPC & Networking

Open

Learning Objectives

By the end of this lesson you should be able to:

  • Explain the VPC: the private network (L263)
  • Explain the subnets: the public and private segments (L263)
  • Explain the security groups: the instance-level firewalls (L263)
  • Explain the egress: the NAT and the VPC endpoints (L263)
  • Explain the AI shape: the network of the L260 backend (L263)

One-Line Definition

VPC & networking is the boundary every AWS service sits inside (L263) — the VPC (the private network, L263), the subnets (the segments: the public for the front door L267, the private for the compute L264 and the data L268, L263), the security groups (the instance-level firewalls, L263), and the egress (the NAT gateway or the VPC endpoint for the outbound calls like Bedrock L278, L263) — the L172 baseline's network layer (L172, L263).

The one-sentence interview answer: "The VPC is the private network every AWS service sits inside (L263). It's segmented into subnets (L263): the public subnets hold the front door — the API Gateway (L267) and the load balancer — things the internet must reach (L263); the private subnets hold the compute and the data — the EC2 (L264), the RDS (L268), the ECS tasks (L271) — things the internet must not reach (L263). The firewalls are layered: the security groups (L263) — instance-level, allow-only rules — and the NACLs (L263) — subnet-level, stateless rules. The egress: the private resources reach the internet — the model calls to Bedrock (L278) — through the NAT gateway (L263) or, better, a VPC endpoint that never leaves the AWS network (L263). The AI shape: the front door public, the data private, the model calls through the endpoint (L263) — the L260 backend, networked (L263)."

Mental Model

Think of the VPC as the office building with locked floors. The building (the VPC, L263) is the private network — only the tenants inside may move around (L263). The floors (the subnets, L263) are the segments: the lobby (the public subnet, L263) is where the front desk (the gateway, L267) greets the visitors; the offices and the vault (the private subnets, L263) hold the work (the compute, L264) and the records (the data, L268) — not for visitors (L263). The doors (the security groups, L263) are the instance-level locks: each room opens only to the rooms that need it (L263). And the mail chute (the egress, L263) is the controlled way out: the offices reach the outside — the model provider (L278) — through the one chute (the NAT, L263) or a direct private tube (the VPC endpoint, L263). The building works because the lobby is public, the offices are locked, and the exit is controlled (L263).

   the building (the VPC, L263)
   ┌────────────────────────────────────────────────────────┐
   │ the lobby (the public subnet, L263) — the front desk    │
   │ (the gateway, L267)                                     │
   │ the offices (the private subnet, L263) — the compute    │
   │ (L264), the data (L268)                                 │
   │ the doors (the security groups, L263) — the locks       │
   │ the mail chute (the egress, L263) — the NAT / endpoint  │
   └────────────────────────────────────────────────────────┘

The mental model is the building: the lobby, the locked floors, the doors, and the mail chute (L263).

Visual Flow — One Request Through the Network

   the internet (L263)
        │
        ▼
   ┌────────────────── THE PUBLIC SUBNET (L263) ──────────────────────┐
   │  the front door: the API Gateway (L267) · the load balancer     │
   │  the security group: 443 from the internet, to the gateway (L263)│
   └──────────────────────────┬───────────────────────────────────────┘
                              ▼  (the internal call, L263)
   ┌────────────────── THE PRIVATE SUBNET (L263) ─────────────────────┐
   │  the compute (L264, L266) · the data (L268) · the queues (L270)  │
   │  the security group: the gateway's group may reach them (L263)   │
   └───────────────┬──────────────────────────────────┬───────────────┘
                   ▼                                  ▼
   ┌────────────────────────┐   ┌──────────────────────────────────┐
   │ the egress (L263)      │   │ the model access (L278)          │
   │ the NAT gateway (L263) │   │ the VPC endpoint — the private   │
   │ for the internet calls │   │ tube, never leaving AWS (L263)   │
   └────────────────────────┘   └──────────────────────────────────┘

The flow is the network: public subnet → private subnet → controlled egress (L263).

How It Works — The Network, Part by Part

  • The VPC (L263). The private network — with its own CIDR (the address range) and its own routing (L263). Every service sits inside one (L263).
  • The subnets (L263). The segments: the public subnets — with a route to the internet gateway — hold the front door (L267); the private subnets — without it — hold the compute (L264) and the data (L268) (L263).
  • The security groups (L263). The instance-level firewalls — allow-only, stateful (L263): the gateway's group allows 443 from the internet (L263); the compute's group allows the traffic from the gateway's group (L263).
  • The NACLs (L263). The subnet-level firewalls — stateless, numbered rules (L263): the subnet's extra layer (L263).
  • The egress (L263). The private resources reach the outside: the NAT gateway — the shared outbound address — for the internet calls (L263); the VPC endpoint — the private connection to the AWS services like Bedrock (L278) — never leaving the AWS network (L263).

Note

The security group is the senior tool (L263). The NACL is the subnet's coarse layer (L263); the security group is the instance's precise layer (L263) — allow-only, stateful, and referenceable (L263). The senior design puts the precision in the security groups (L263): the gateway's group, the compute's group, the database's group — each allowing exactly the traffic it needs (L263). The NACL is the extra belt for the compliance requirements (L263).

Real Project Usage

  • A serverless AI stack (L283). The API Gateway (L267) in the public layer, the Lambda (L266) in the private subnets (L263), the model calls (L278) through the VPC endpoint (L263).
  • A containerized backend (L271). The ECS tasks (L271) in the private subnets (L263), the load balancer in the public (L263), the RDS (L268) in the private with a security group (L263).
  • A RAG pipeline (L280). The ingestion (L280) reading the S3 (L265) in the private subnets (L263), the vector store (L268) with its own security group (L263).
  • A regulated workload (L371). The private subnets for the data (L263), the egress through the endpoints (L263), the NACL for the compliance (L263).
  • Anything AWS (L263). The network is the boundary (L263) — the L172 baseline's network layer (L263).

The through-line: the network is the boundary — the front door public, the work private, the egress controlled (L263).

Interview Explanation

Say it in four moves:

  1. The VPC. "The private network every service sits inside (L263)."
  2. The subnets. "The public — the front door (L267); the private — the compute and the data (L264, L268)."
  3. The security groups. "The instance-level, allow-only firewalls (L263)."
  4. The egress. "The NAT for the internet, the VPC endpoint for the AWS calls (L278) — never leaving the network (L263)."

Senior-Level Insights

  • The network is the isolation (L320). The senior answer isolates the tenants (L320) with the network: the per-tenant subnets and security groups (L263) — the L320 isolation, VPC-shaped (L263).
  • The security group is the review surface (L263). The senior review reads the security groups (L263): what may reach the database (L268), the compute (L264), the model endpoint (L278). The group rules are the attack surface (L263).
  • The endpoint is the data path (L263). The model calls (L278) through the VPC endpoint (L263) never leave the AWS network (L263) — the L312 data path, private (L263).
  • The egress is the blast-radius control (L263). The one NAT (L263), the scoped endpoints (L263) — the L314 agency, network-shaped (L263).
  • The multi-AZ spread is the network's availability (L261). The subnets spread across the AZs (L261) — the L286 availability, networked (L263).

Common Mistakes

  • Everything public (L263). The database (L268) in a public subnet (L263) — the L313 exposure (L263).
  • The security group wide open (L263). 0.0.0.0/0 on the database's group (L263) — the L172 baseline lost (L263).
  • The egress unplanned (L263). No NAT, no endpoint (L263) — the model calls (L278) fail or the traffic leaks through a proxy (L263).
  • The data through the internet (L263). The model calls (L278) and the DB traffic (L268) over the internet (L263) — the endpoint is the private path (L263).
  • The single-AZ subnets (L261). All the subnets in one AZ (L261) — the L286 availability lost (L263).

Best Practices

  • Keep the data private (L263) — the compute (L264) and the data (L268) in the private subnets (L263).
  • Scope the security groups (L263) — allow-only, by the group references (L263).
  • Use the VPC endpoints (L263) — the model calls (L278) and the AWS services never leave the network (L263).
  • Spread the subnets across the AZs (L261) — the availability (L286).
  • Layer the NACL for the compliance (L263) — the subnet's extra belt (L263).

Interview Questions

Q: Walk me through a VPC.

A: The private network (L263). The subnets: the public — the front door, the gateway (L267); the private — the compute (L264) and the data (L268) (L263). The firewalls: the security groups — instance-level, allow-only (L263); the NACLs — subnet-level (L263). And the egress: the NAT for the internet, the VPC endpoints for the AWS calls (L278) (L263).

Q: Why keep the data in the private subnets?

A: Because it's the L172 baseline (L172): the data (L268) must not be reachable from the internet (L263). The private subnets have no internet route (L263); the only path in is through the front door (L267) and its security group (L263). The exposure is the network's most common breach (L263).

Q: How does the private compute reach the model?

A: Two ways (L263). Through the NAT gateway — the outbound address — for the internet calls (L263); or through a VPC endpoint — the private connection to Bedrock (L278) — which never leaves the AWS network (L263). The endpoint is the senior answer: private, fast, and auditable (L263).

Q: What's the difference between a security group and a NACL?

A: The scale and the state (L263). The security group is instance-level, allow-only, and stateful (L263); the NACL is subnet-level, has allow and deny rules, and is stateless (L263). The security group is the precision tool (L263); the NACL is the subnet's extra belt (L263).

Follow-Up Questions

  • What's the VPC (L263)?
  • What are the subnets (L263)?
  • What's a security group (L263)?
  • What's the egress (L263)?
  • Why the VPC endpoints (L263)?

Comparison Table — Public vs Private Subnet

Public subnet (L263)Private subnet (L263)
Reach (L263)the internet routeno internet route (L263)
Contents (L263)the front door: the gateway (L267)the compute (L264), the data (L268)
Egress (L263)direct (L263)the NAT / the endpoint (L263)
Risk (L263)the exposed surface (L263)the L172 baseline's data (L172, L263)

The senior read: the right column is the data's home — unreachable from the internet (L263).

Code Example — The Network, Declared

// The network for the L260 backend (L260, L263).
// THE VPC (L263) — the private network with its own CIDR (L263).
const vpc = { cidr: '10.0.0.0/16' };

// THE SUBNETS (L263) — the public and the private layers.
// The public: the front door (L267). The private: the work (L264, L268).
const publicSubnets  = ['10.0.1.0/24', '10.0.2.0/24'];   // AZ-a, AZ-b (L261)
const privateSubnets = ['10.0.11.0/24', '10.0.12.0/24']; // AZ-a, AZ-b (L261)

// THE SECURITY GROUPS (L263) — allow-only, by reference (L263).
const gatewaySg = {
  ingress: [{ from: 443, to: 443, cidr: '0.0.0.0/0' }],      // the HTTPS (L263)
  egress:  [{ from: 0, to: 65535, cidr: '10.0.0.0/16' }],    // the internal (L263)
};
const dataSg = {
  ingress: [{ from: 5432, to: 5432, group: gatewaySg }],      // the gateway only (L263)
  egress:  [],                                                // no outbound (L263)
};

// THE EGRESS (L263) — the model calls never leave the network (L278).
const bedrockEndpoint = { service: 'bedrock', private: true }; // the VPC endpoint (L263)
What the reader must SEE — the network, declared:

  vpc cidr 10.0.0.0/16      → the private network (L263)
  public / private subnets  → the layers: the door, the work (L263)
  gatewaySg: 443 in         → the front door's group (L263)
  dataSg: 5432 from gateway → the data's group — the gateway only (L263)
  bedrockEndpoint           → the private model path (L263, L278)

  The front door public, the data private, the egress controlled.

Tip

The pair that defines the network: the private subnet (where the data lives, L263) and the scoped security group (who may reach it, L263). Front door public, data private, egress controlled — the L172 baseline, networked (L263).

Performance Notes

  • The network is the latency's frame (L151). The region (L261), the AZs (L261), and the subnets (L263) — the traffic paths are the latency (L151).
  • The endpoint is the fast path (L263). The VPC endpoint (L263) to Bedrock (L278) — no NAT, no internet hop (L263) — the model calls (L151) as fast as the network allows (L263).
  • The security groups are the zero-cost layer (L263). The instance-level rules (L263) cost nothing and add no latency (L263).
  • The NAT is the bottleneck (L263). The one NAT gateway (L263) — the shared outbound path (L263) — the throughput (L333) is its limit (L263).

Debugging Scenarios

SymptomFirst check (L263)The lever
The Lambda can't reach the database (L268)The security group (L263)The data's group: the gateway's group allowed (L263)
The model call times out (L278)The egress (L263)The VPC endpoint (L263)
The internet calls failThe NAT (L263)The NAT gateway in the public subnet (L263)
The data is exposedThe subnet (L263)The private subnets (L263)
The traffic is slowThe path (L263)The endpoint, not the NAT (L263)

Quick Revision Notes

  • VPC & networking = the boundary (L263): the VPC, the subnets, the security groups, the egress.
  • The VPC: the private network (L263).
  • The subnets: the public for the door (L267), the private for the work (L264, L268).
  • The security groups: the instance-level, allow-only firewalls (L263).
  • The egress: the NAT (L263) and the VPC endpoints (L263) — the private model path (L278).

Cheat Sheet

VPC & NETWORKING = the boundary every service sits inside

THE VPC (L263)
  the private network — the CIDR, the routing
  the subnets: the public (the door, L267) · the private (the work, L264, L268)

THE FIREWALLS (L263)
  the security groups — instance-level, allow-only, stateful
  the NACLs — subnet-level, stateless, numbered

THE EGRESS (L263)
  the NAT gateway — the shared outbound address
  the VPC endpoint — the private AWS path (L278), never leaving the network

THE AI SHAPE (L263)
  the front door public (L267) · the data private (L268)
  the model calls through the endpoint (L278)
  the subnets spread across the AZs (L261)

INTERVIEW, 4 MOVES
  1 vpc    "the private network (L263)"
  2 subnets "public for the door, private for the work (L263)"
  3 groups "instance-level, allow-only (L263)"
  4 egress "the NAT, the endpoints — the model path private (L263, L278)"

Key Takeaways

Recap

  • VPC & networking is the boundary every AWS service sits inside (L263): the VPC (L263), the subnets (L263), the security groups (L263), and the egress (L263)
  • The VPC (L263) is the private network; the subnets (L263) segment it — the public for the front door (L267), the private for the compute (L264) and the data (L268)
  • The security groups (L263) are the instance-level, allow-only firewalls — the gateway's group, the compute's group, the data's group (L263)
  • The egress (L263) is the controlled way out — the NAT for the internet, the VPC endpoints for the AWS calls (L278) that never leave the network
  • The network is the L172 baseline's network layer (L172, L263): the data private, the groups scoped, the egress controlled
  • The L260 backend (L260) runs on this network: the front door public, the data private, the model path through the endpoint (L263)

Check your understanding

Answer each one out loud. Then rate yourself honestly.

0/8
1

What's the VPC (L263)?

2

What are the subnets (L263)?

3

What's a security group (L263)?

4

What's the egress (L263)?

5

Why keep the data private (L263)?

6

What's a VPC endpoint (L263)?

7

How do the security group and the NACL differ (L263)?

8

What is the L172 baseline, networked (L263)?

A Closing Note — The Building, Walled

You now hold the network: the VPC, the subnets, the security groups, and the egress — with the data private and the model path controlled. The map has walls — and the L260 backend sits safely inside (L263).

Next: the baseline compute — EC2 (L264).