What Is an AWS VPC and How Does It Secure Resources?
AWS VPC security by layer: subnets, routes, security groups, NACLs, endpoints, Block Public Access and flow logs, with CLI examples and an audit checklist.
An Amazon VPC is a logically isolated virtual network in your AWS account where you place resources such as EC2 instances and databases. It secures them in layers: private subnets and route tables decide what can be reached at all, security groups and network ACLs filter traffic, VPC endpoints keep AWS service traffic off the internet, and flow logs record what happened.
A VPC is isolated by default, but the default settings still need a design. This guide walks the layers in the order a packet meets them, shows the commands to build and audit each one, and lists the mistakes that expose private resources. It was checked against the AWS VPC documentation in November 2026. For deeper dives, see our posts on public and private subnet design and on security groups versus NACLs.
Key takeaways
- A VPC does not secure anything by being a VPC. Security comes from how you design subnets, routes, filters and access.
- Security groups are stateful and allow-only. Network ACLs are stateless, evaluated in rule-number order, and can allow or deny.
- A subnet is public only if its route table sends traffic to an internet gateway. Keep databases and application servers in subnets without that route.
- Gateway endpoints for S3 and DynamoDB, and interface endpoints powered by AWS PrivateLink, let private resources reach AWS services without an internet path.
- VPC Block Public Access can block internet traffic account-wide, with explicit exclusions.
- VPC Flow Logs, Reachability Analyzer and Network Access Analyzer help you prove what the network allows instead of assuming.
What a VPC is
A virtual private cloud is your own section of the AWS network. You choose an IPv4 CIDR block (between /16 and /28 in size), split it into subnets in different Availability Zones, and attach gateways and route tables. Resources inside can talk to each other over private addresses. Nothing outside can reach them unless you create a path.
Every account also starts with a default VPC in each Region. A default VPC comes with a public subnet in each Availability Zone, an internet gateway and DNS settings, so you can launch instances immediately. AWS describes it as suitable for getting started quickly and for public instances such as a simple website. For anything with real data, build a custom VPC instead.
Layer 1: network design, subnets and routes
Design comes first because filters cannot fix a layout that exposes everything. Use at least two Availability Zones for production, as AWS recommends in its VPC security best practices, and split each zone into tiers:
| Tier | Example contents | Route to internet | Inbound path |
|---|---|---|---|
| Public subnet | Load balancer, NAT gateway | Internet gateway | Internet to load balancer only |
| Private application subnet | EC2, containers | None directly; outbound through a NAT gateway if needed | From the load balancer's security group |
| Private data subnet | RDS, ElastiCache | None | From the application tier's security group |
The deciding factor is the route table. A subnet whose route table has a route to an internet gateway is public. Private subnets do not have that route. Instances that only need outbound internet access, for example to download patches, can use a NAT gateway placed in a public subnet. Read how route tables and internet gateways work together and the role of NAT gateways for the mechanics.
AWS does not support direct internet access from the VPC CIDR block itself, even for a publicly routable range. Internet access always needs a gateway. This is part of the isolation model.
Layer 2: security groups at the resource
A security group is a virtual firewall attached to a resource, such as an instance's network interface. Key properties from the AWS documentation:
- Rules are allow-only. You cannot write a deny rule.
- Until you add inbound rules, no inbound traffic is allowed.
- Security groups are stateful. If a request is allowed in, the response is allowed out regardless of outbound rules.
- A new security group has an outbound rule that allows all outbound traffic. Remove it and add specific outbound rules if you want tighter control.
- If you attach several groups to a resource, their rules are combined.
- You can reference another security group as the source, instead of an IP range.
Referencing security groups is the habit that pays off most. Instead of allowing port 5432 from the whole application subnet CIDR, allow it from the application tier's security group. Autoscaled instances then gain access automatically, and nothing else does.
Every VPC has a default security group. Its default rules allow inbound traffic from other resources in the same group and all outbound traffic. AWS recommends creating specific groups instead of relying on the default one, because resources launched without a group choice are placed in the default group.
# Web tier: HTTPS from anywhere
aws ec2 create-security-group --group-name web-sg --description "Web tier" --vpc-id vpc-0abc1234567890def
aws ec2 authorize-security-group-ingress --group-id sg-0aaa1111bbbb2222c \
--protocol tcp --port 443 --cidr 0.0.0.0/0
# App tier: port 8080 only from the web tier's security group
aws ec2 create-security-group --group-name app-sg --description "App tier" --vpc-id vpc-0abc1234567890def
aws ec2 authorize-security-group-ingress --group-id sg-0ccc3333dddd4444e \
--protocol tcp --port 8080 --source-group sg-0aaa1111bbbb2222c
Layer 3: network ACLs at the subnet
A network ACL (NACL) filters traffic entering and leaving a subnet. Differences from security groups:
| Feature | Security group | Network ACL |
|---|---|---|
| Applies to | Resource (network interface) | Subnet |
| State | Stateful | Stateless: return traffic needs its own rule |
| Rule types | Allow only | Allow and deny |
| Evaluation | All rules combined | In order from the lowest rule number; first match wins |
| Default | No inbound allowed, all outbound allowed | Default NACL allows all traffic; a final rule (*) denies anything unmatched |
| Association | Many groups per resource | One NACL per subnet |
Rule numbers run from 1 to 32766, and AWS suggests leaving gaps (10, 20, 30) so you can insert rules later. Use NACLs for coarse controls such as blocking a known bad range for a whole subnet, or as a second layer for compliance. Because they are stateless, remember ephemeral ports for return traffic, which is a common cause of confusing outages. Our post on securing VPCs with NACLs and security groups includes rule examples.
Layer 4: keep AWS service traffic private with endpoints
Instances in a private subnet often need S3, DynamoDB, ECR, Secrets Manager or CloudWatch. Without help, that traffic goes out through a NAT gateway and across the internet path. VPC endpoints remove that dependency.
- Gateway endpoints support Amazon S3 and DynamoDB. You add them as a target in route tables. There is no additional charge for gateway endpoints. They do not allow access from on-premises networks or peered VPCs in other Regions; use an interface endpoint for those cases.
- Interface endpoints use AWS PrivateLink to give services a private IP address in your subnet, so clients reach them without an internet gateway or NAT device. They carry a cost.
Endpoint policies and bucket policies can then restrict which principals and buckets are reachable through the endpoint. That limits data exfiltration paths as well as exposure.
Layer 5: account-wide guardrails
VPC Block Public Access (BPA) is a centralised control that prevents internet access to VPC resources across an account in a Region. It has two modes. Bidirectional blocks all traffic to and from internet gateways and egress-only internet gateways. Ingress-only blocks inbound internet traffic and still allows NAT gateways and egress-only gateways, which only start outbound connections. You can create exclusions for specific VPCs or subnets that must stay public, such as a subnet for a public load balancer. BPA is useful as a safety net: even if someone attaches an internet gateway by mistake, the account policy still blocks the traffic.
Combine it with IAM controls that limit who can create internet gateways, edit route tables or change security groups. Network security depends on those permissions as much as on the rules themselves. See also the AWS guidance on the shared responsibility model.
Layer 6: visibility and verification
- VPC Flow Logs capture information about IP traffic to and from network interfaces and can publish to CloudWatch Logs, S3 or Amazon Data Firehose. Flow log data is collected outside the path of your traffic, so it does not affect throughput or latency. Use it to find overly restrictive rules and unexpected traffic.
- Reachability Analyzer tests connectivity between a source and destination and, when traffic is blocked, identifies the blocking component such as a security group, network ACL or route table.
- Network Access Analyzer finds unintended network access to resources in your VPCs. AWS lists it in its VPC best practices.
- AWS Network Firewall filters inbound and outbound traffic at a deeper level, and Amazon GuardDuty uses flow logs among other sources to detect potential threats. Both appear in AWS's best-practice list.
- CloudWatch can alert on flow log patterns, such as a spike in rejected connections. Our guide to automating alerts with CloudWatch shows how to wire alarms.
# Turn on flow logs for a VPC, delivered to CloudWatch Logs
aws ec2 create-flow-logs --resource-type VPC --resource-ids vpc-0abc1234567890def \
--traffic-type ALL --log-destination-type cloud-watch-logs \
--log-group-name /vpc/flow-logs \
--deliver-logs-permission-arn arn:aws:iam::111122223333:role/flow-logs-role
Common mistakes that expose private resources
- Putting databases in a public subnet because it was faster for testing, then leaving them there.
- Opening SSH (port 22) or RDP to 0.0.0.0/0. Use AWS Systems Manager Session Manager or a bastion with a narrow source range instead.
- Relying on the default security group, which allows all traffic among its members.
- Writing NACL rules without allowing return traffic on ephemeral ports.
- Allowing broad outbound rules everywhere, which makes data exfiltration easy.
- Forgetting IPv6. Public IPv6 addresses in AWS are globally unique and routable, so IPv6 rules need the same care as IPv4. Our post on IPv6 in cloud environments covers this.
- Not logging. If flow logs are off, you cannot investigate or prove what traffic occurred.
A quick audit checklist
- List route tables with a route to an internet gateway and confirm that only intended subnets use them.
- List security groups with 0.0.0.0/0 or ::/0 on ports other than 80 and 443.
- Confirm that no resource uses the default security group unless intended.
- Check that data and application subnets have no internet gateway route.
- Confirm gateway endpoints exist for S3 and DynamoDB where private instances use them.
- Confirm flow logs are enabled and someone reads them.
- Run Reachability Analyzer on one critical path, for example from the internet to the database, and confirm it reports not reachable.
To build and break these controls in a lab, take our AWS Solutions Architect Associate training in the Kharadi, Pune classroom or live online.
Frequently asked questions
What is a VPC in AWS?
A Virtual Private Cloud is a logically isolated virtual network inside your AWS account. You define its IP range, subnets, route tables and gateways, and launch resources into it. Traffic reaches those resources only through paths you create.
How does a VPC secure AWS resources?
Through layers: isolation by default, private subnets without internet routes, stateful security groups on resources, stateless network ACLs on subnets, endpoints for private access to AWS services, optional Block Public Access, and flow logs for visibility.
What is the difference between a security group and a network ACL?
A security group is attached to a resource, is stateful and allows only. A network ACL is attached to a subnet, is stateless, supports allow and deny rules, and is evaluated by rule number. Use security groups for most application rules and NACLs for coarse subnet-level controls.
Is the default VPC secure enough for production?
Usually not. The default VPC has public subnets and an internet gateway so you can start quickly. Production workloads normally use a custom VPC with private subnets for application and data tiers.
What is a public subnet in AWS?
A subnet whose route table has a route to an internet gateway. A subnet without that route is private, even if it has no other special setting.
Do I need a NAT gateway for private subnets?
Only if private instances must start connections to the internet, for example for package updates. For AWS services such as S3 and DynamoDB, gateway endpoints avoid NAT entirely. IPv6 workloads can use an egress-only internet gateway for outbound access.
How can I check who can reach my database?
Review the database's security group sources, confirm its subnet has no internet gateway route, and run Reachability Analyzer from the suspected source to the database port. Network Access Analyzer can also scan for unintended access across the VPC.
Official references
What's Your Reaction?
Like
0
Dislike
0
Love
0
Funny
0
Angry
0
Sad
0
Wow
0