Amazon VPC (Virtual Private Cloud) là mạng ảo riêng biệt, cô lập trong AWS cloud, cho phép bạn kiểm soát hoàn toàn môi trường mạng: chọn IP range (CIDR), tạo subnet, cấu hình route table, gateway.
Public subnet là subnet có route đến Internet Gateway (IGW), các resource trong đó (EC2 với public IP) có thể nhận kết nối từ internet trực tiếp — thường dùng cho load balancer, bastion host, NAT Gateway. Private subnet không có route trực tiếp ra internet; resource muốn ra internet phải đi qua NAT Gateway (một chiều, ra ngoài được nhưng không nhận được kết nối từ ngoài) — thường dùng cho app server, database, Lambda.
Phân tách giúp giảm attack surface: database không bao giờ expose trực tiếp ra internet, chỉ app server trong private subnet mới kết nối được tới DB. Best practice: mỗi AZ có 1 public + 1 private subnet; dùng VPC Flow Logs để audit traffic; dùng VPC Endpoint (PrivateLink) để kết nối AWS services (S3, DynamoDB) mà không cần ra internet.
Amazon VPC (Virtual Private Cloud) is an isolated virtual network within AWS cloud, giving you full control over your network environment: choosing IP ranges (CIDR), creating subnets, configuring route tables, and gateways.
A public subnet has a route to an Internet Gateway (IGW), so resources within it (EC2 instances with a public IP) can accept inbound connections from the internet — commonly used for load balancers, bastion hosts, and NAT Gateways. A private subnet has no direct route to the internet; resources that need outbound internet access must go through a NAT Gateway (one-way: outbound only, no inbound connections from outside) — commonly used for app servers, databases, and Lambda.
Separation reduces the attack surface: databases are never directly exposed to the internet, and only app servers in the private subnet can connect to the DB. Best practices: each AZ should have one public and one private subnet; use VPC Flow Logs to audit traffic; use VPC Endpoints (PrivateLink) to connect to AWS services (S3, DynamoDB) without going through the internet.