Skip to content

Production-grade AWS VPC project featuring a full 3-tier architecture with public, private and database subnets, bastion access, NAT Gateway, Security Groups, custom NACLs, and full end-to-end connectivity testing.

Notifications You must be signed in to change notification settings

usmanuh/aws-multi-tier-vpc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

🏗️ Multi-Tier AWS VPC Architecture — Secure, Scalable and Fully Validated

Why this matters: This architecture is used by companies for applications requiring strict network isolation, PCI compliance or multi-tier security. It demonstrates production-grade cloud infrastructure design.

This project demonstrates the design and implementation of a production-style AWS VPC with public, private and database tiers, complete with bastion access, NAT gateway, custom Security Groups, custom Network ACLs and full connectivity testing.

This project was built completely hands-on using the AWS console and tested end-to-end using SSH, ProxyJump and curl commands.


📌 Architecture Diagram

Architecture Diagram


🚀 1. Project Overview

This project implements a 3-tier VPC architecture commonly used in production environments:

  • Public Subnets → bastion host, NAT gateway, future load balancer
  • Private Subnets → application EC2 instances
  • Database Subnets → isolated DB tier
  • NAT Gateway → secure outbound internet for private instances
  • Internet Gateway → inbound/outbound for public subnets
  • Custom Security Groups & NACLs
  • SSH bastion flow & NAT Gateway testing

This is the exact type of network design required for modern cloud applications.


🛠️ Tech Stack

AWS Services:

  • VPC (subnets, route tables, NACLs)
  • EC2 (Amazon Linux 2)
  • Internet Gateway
  • NAT Gateway
  • Security Groups

Tools & Protocols:

  • SSH / ProxyJump
  • Bash / curl
  • AWS Console

📁 Project Structure

.
├── diagram/
│   └── vpc-architecture.jpeg
├── screenshots/
│   ├── public-rt-subnet-association.jpeg
│   ├── app-nacl-inbound.jpeg
│   ├── app-nacl-outbound.jpeg
│   ├── db-nacl-inbound.jpeg
│   ├── db-nacl-outbound.jpeg
│   ├── ssh-failure.jpeg
│   ├── ssh-success.jpeg
│   ├── private-ec2-access.jpeg
│   └── curl-nat-test.jpeg
└── README.md

📋 Prerequisites

  • AWS Account with appropriate IAM permissions
  • SSH key pair created in eu-west-2 region
  • Basic understanding of VPC, subnets and routing concepts
  • AWS CLI or Console access

🌐 2. VPC & Subnet Design

VPC CIDR: 10.0.0.0/16
AZs Used: eu-west-2a and eu-west-2b

Public Subnets

  • 10.0.1.0/24 (eu-west-2a)
  • 10.0.2.0/24 (eu-west-2b)

Private Subnets

  • 10.0.11.0/24 (eu-west-2a)
  • 10.0.12.0/24 (eu-west-2b)

Database Subnets

  • 10.0.21.0/24 (eu-west-2a)
  • 10.0.22.0/24 (eu-west-2b)

📸 Subnet Associations

Public Subnet Associations

📌 This shows both public subnets correctly associated with the Public Route Table.


🚪 3. Route Tables

Public Route Table

  • 0.0.0.0/0 → Internet Gateway

Private Route Table

  • 0.0.0.0/0 → NAT Gateway

This ensures the private tier can reach the internet securely without exposing instances publicly.


🌍 4. Internet Gateway & NAT Gateway

  • A dedicated Internet Gateway was created and attached to the VPC
  • A NAT Gateway was deployed inside Public Subnet 1 with an Elastic IP

This enables application servers to download updates, reach package repositories and access APIs securely.


🔐 5. Security Groups (Least Privilege)

Web-SG

  • Allow 80/443 from anywhere
  • Allow 22 only from my IP

App-SG

  • Allow app port 8080 ONLY from Web-SG
  • Allow SSH ONLY from Web-SG

DB-SG

  • Allow MySQL 3306 ONLY from App-SG

This ensures traffic flows strictly tier → tier, never bypassing layers.


🧱 6. Network ACLs (Subnet-Level Security)

Custom NACLs were created for:

App-NACL

App NACL Inbound App NACL Outbound

DB-NACL

DB NACL Inbound DB NACL Outbound

These enforce subnet-level security:

  • Only app subnets can reach DB subnet
  • Only necessary ports allowed
  • All other inbound traffic denied

💻 7. EC2 Setup & SSH Access (Bastion Host)

A bastion host was created in a public subnet.

SSH Attempt (Failure Before Fixing SG/NACL)

SSH Fail

This failure was due to strict NACL rules — part of the learning process.

SSH Success (After Fixes)

SSH Success

Once NACL and SG rules were corrected, SSH access worked perfectly.


🔐 8. Accessing Private EC2 via Bastion (ProxyJump)

# Template - replace with your actual IPs
ssh -i linux-project-key.pem \
  -J ec2-user@BASTION_PUBLIC_IP \
  ec2-user@PRIVATE_INSTANCE_IP

# Example
ssh -i linux-project-key.pem \
  -J ec2-user@18.130.XXX.XXX \
  ec2-user@10.0.11.244

Screenshot: Logged Into Private Subnet EC2

Private EC2 Access

This validates the bastion → private flow is functioning securely.


🌐 9. NAT Gateway Validation

Inside the private EC2 instance:

curl -I https://amazon.com
curl -I https://checkip.amazonaws.com

Screenshot: curl Working Through NAT

curl NAT Test

📌 This confirms outbound internet works from a private subnet using the NAT Gateway.


🧪 10. End-to-End Validation Summary

✅ Public subnet → Internet (via IGW)
✅ Private subnet → Internet (via NAT Gateway)
✅ Bastion → App EC2 via SSH
✅ App EC2 → DB subnets allowed
✅ Tier isolation enforced via SGs & NACLs
✅ All traffic flows correct and secure

This matches real-world production architecture.


🛠️ 11. Troubleshooting & Lessons Learned

🔸 Issue: SSH timeout to bastion host

  • Cause: Incorrect inbound rules
  • Fix: Allowed SSH from my public IP only

🔸 Issue: NAT Gateway curl failed

  • Cause: Private subnet accidentally associated with wrong route table
  • Fix: Re-associated subnet to Private-RT

🔸 Issue: Private instance SSH access failed

  • Cause: Missing ProxyJump configuration
  • Fix: Used correct -J flag and ensured SG/NACL allowed traffic

These demonstrate real-world problem-solving and understanding of AWS networking.


💰 12. Cost Considerations

  • NAT Gateway: Charges per hour + data transfer costs
  • EC2 instances: t2.micro eligible for free tier
  • Elastic IP: Free when attached, charges when idle
  • Main cost driver: NAT Gateway if left running continuously

💡 Tip: Stop EC2 instances and delete NAT Gateway when not in use to minimize costs. Always check AWS pricing calculator for your specific region.


🔒 13. Security Notes

  • ⚠️ Never commit .pem files to Git
  • Bastion SSH limited to your IP only
  • Consider AWS Systems Manager Session Manager for production (removes SSH key management)
  • Regularly rotate SSH keys and review Security Group rules
  • Enable VPC Flow Logs for network traffic monitoring

📈 14. Next Steps (Future Enhancements)

Planned improvements:

  • Add an Application Load Balancer
  • Configure Auto Scaling Group
  • Add RDS Multi-AZ database
  • Use Systems Manager Session Manager (remove SSH entirely)
  • Add CloudWatch Dashboards
  • Use Terraform or CloudFormation for end-to-end IaC
  • Implement VPC Flow Logs for monitoring
  • Add AWS WAF for web application firewall

📚 What I Learned

  • Designing multi-tier VPC architectures for production environments
  • Implementing defense-in-depth with Security Groups AND NACLs
  • Troubleshooting network connectivity issues systematically
  • Using bastion hosts and ProxyJump for secure access
  • Understanding the difference between stateful (SG) and stateless (NACL) firewalls
  • NAT Gateway configuration for private subnet internet access

🏷️ GitHub Topics

aws vpc cloud-security cloud-architecture nat-gateway bastion-host nacl security-groups linux networking


🤝 Connect

If you have questions or suggestions, feel free to open an issue or reach out!


📄 License

This project is for educational purposes. Feel free to use and modify as needed.


Built with ☁️ by Usman Ul-Haq

About

Production-grade AWS VPC project featuring a full 3-tier architecture with public, private and database subnets, bastion access, NAT Gateway, Security Groups, custom NACLs, and full end-to-end connectivity testing.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published