Skip to content

Build a secure AWS VPC with Bastion Host and Private EC2 — full hands-on networking project under AWS Free Tier, including NGINX setup, SSH tunneling, and cleanup guide.

License

Notifications You must be signed in to change notification settings

MaheshShukla1/aws-vpc-bastion-private-ec2-architecture

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

🚀 AWS VPC Architecture with Bastion Host & Private EC2

🔐 Secure SSH Access | NGINX Deployment | AWS Free Tier Safe

AWS Free Tier Architecture License: MIT Region Made with ❤️ on AWS

A hands-on, production-style AWS networking project — build a secure Virtual Private Cloud (VPC) with a public Bastion Host to SSH into private EC2 instances, all within AWS Free Tier limits.
Perfect for DevOps engineers, cloud learners, and AWS certification aspirants.


📚 Table of Contents


🎯 Overview

Architecture Flow:

Your Laptop → (SSH) → Bastion Host (Public Subnet) → (SSH) → Private EC2 (Private Subnet)

This project demonstrates secure access control, subnet isolation, and internal communication inside AWS — exactly how production VPCs are designed in real-world cloud setups.


🏗️ Architecture Diagram

AWS VPC Architecture with Bastion Host and Private EC2

Includes:

  • ✅ Custom VPC (10.0.0.0/16)
  • ✅ Public + Private Subnets
  • ✅ Bastion Host with restricted SSH
  • ✅ Private EC2 (no public IP)
  • ✅ Route Tables, Security Groups, and NGINX servers

📸 Visual Reference (Screenshots)

VPC Creation

VPC Created

Subnets

Public & Private Subnets
Private Subnet Details

Internet Gateway

IGW Attached

Route Tables

Public Route Table
Private Route Table

Security Groups

Security Groups Overview
Private Security Group Details

EC2 Instances

Bastion EC2
Private EC2

SSH Connectivity

Laptop → Bastion
Bastion → Private EC2

✨ Key Highlights

Feature Description
🟢 Free Tier Safe No NAT Gateway — uses Bastion for internal access
🌍 Region ap-south-1 (Mumbai)
💻 Instances 2× Amazon Linux 2023 (t2.micro)
🔐 Security Bastion → open only to your IP
⚙️ Networking Custom VPC with public/private subnets
🧱 Web Server NGINX running on both instances
🧰 Tools Used EC2, VPC, IGW, Route Tables, Security Groups, SSH

🧩 Components Overview

Resource CIDR / Notes
VPC 10.0.0.0/16
Public Subnet 10.0.1.0/24
Private Subnet 10.0.2.0/24
Internet Gateway Attached to VPC
Route Tables Separate for Public & Private
Security Groups Bastion ↔ Private EC2 controlled
SSH Key my-key.pem

⚙️ Setup Guide (Step-by-Step)

⏱️ Time Required: 45–60 minutes
💰 Cost: Free (within AWS Free Tier)
💡 Difficulty: Beginner–Intermediate


Step 1 — Create the VPC

  • Name: project-vpc
  • CIDR: 10.0.0.0/16

Step 2 — Create Subnets

  • Public Subnet: 10.0.1.0/24 — Auto-assign public IP: Yes
  • Private Subnet: 10.0.2.0/24 — Auto-assign public IP: No

Step 3 — Internet Gateway

  • Create IGW: project-igw
  • Attach to project-vpc
    💡 Purpose: Allows internet access only for public subnet resources.

Step 4 — Route Tables

  • Public Route Table: Add route 0.0.0.0/0 → project-igw and associate with public subnet.
  • Private Route Table: Associate with private subnet — no internet route.

Step 5 — Security Groups

Bastion SG (sg-bastion)

Type Port Source
SSH 22 Your public IP (x.x.x.x/32)
HTTP 80 0.0.0.0/0 (optional)

Private SG (sg-private)

Type Port Source
SSH 22 sg-bastion (reference)

✅ Bastion can SSH into Private EC2.
✅ Private EC2 not exposed to internet.


Step 6 — Launch EC2 (Bastion)

  • Public Subnet: public-subnet-1
  • AMI: Amazon Linux 2023
  • Instance Type: t2.micro
  • SG: sg-bastion
  • Key Pair: my-key.pem

Connect from your laptop:

chmod 400 my-key.pem
ssh -i my-key.pem ec2-user@<BASTION_PUBLIC_IP>

Step 7 — Launch Private EC2 (Private Subnet)

Setting Value
Name private-ec2
AMI Amazon Linux 2023
Instance Type t2.micro
Subnet private-subnet-1
Public IP None
SG sg-private
Key Pair my-key.pem

Connect via Bastion (from Bastion shell):

On Bastion

ssh -i my-key.pem ec2-user@<PRIVATE_EC2_IP>

Step 8 — Validate SSH Connectivity

From your Laptop → Bastion (Public EC2):

On Bastion (Public):

chmod 400 mahesh.pem
ssh -i mahesh.pem ec2-user@<BASTION_PUBLIC_IP>

On Private EC2:

ssh -i mahesh.pem ec2-user@<PRIVATE_EC2_IP>

✅ Verify that you can SSH from your laptop to Bastion.
✅ Verify that you can SSH from Bastion into Private EC2.
✅ This confirms your VPC, Subnets, Security Groups, and Bastion Host are configured correctly.

Step 9 — Validate Setup

Use AWS CLI or Console to verify resources:

aws ec2 describe-instances
aws ec2 describe-subnets
aws ec2 describe-security-groups
aws ec2 describe-route-tables

Step 10 — Cleanup (Avoid Charges)

Terminate instances and delete networking resources (or delete via Console):

# Terminate instances
aws ec2 terminate-instances --instance-ids <bastion-id> <private-id>

# Delete networking components
aws ec2 delete-subnet ...
aws ec2 delete-route-table ...
aws ec2 detach-internet-gateway ...
aws ec2 delete-internet-gateway ...
aws ec2 delete-vpc --vpc-id <vpc-id>

Or simply delete everything via AWS Console.

📸 Screenshots Guide (Filenames)

Step Screenshot Description
1 vpc-created.png Custom VPC creation confirmed
2 subnets.png & subnets-private.png Public & Private subnets with CIDRs
3 igw-attached.png Internet Gateway attached
4 route-table-public.png & route-table-private.png Public/Private route tables
5 security-groups.png & private-security-group.png Security Groups rules
6 ec2-bastion.png Bastion EC2 running
7 private-ssh.png Private EC2 running
8 ssh-bastion-terminal.png & private-terminal.png SSH: Laptop → Bastion → Private EC2

📚 Learning Outcomes

Feature Description
🟢 Free Tier Safe No NAT Gateway — uses Bastion for internal access
🌍 Region ap-south-1 (Mumbai)
💻 Instances 2× Amazon Linux 2023 (t2.micro)
🔐 Security Bastion → open only to your IP
⚙️ Networking Custom VPC with public/private subnets
🧱 Access Bastion → Private EC2 SSH only
🧰 Tools Used EC2, VPC, IGW, Route Tables, Security Groups, SSH

🧰 Tech Stack

  • Amazon VPC

  • EC2 (Amazon Linux 2023)

  • Internet Gateway

  • Route Tables

  • Security Groups

  • SSH

📂 Project Structure

aws-vpc-bastion-architecture/
├── README.md
├── architecture.png
└── screenshots/
    ├── vpc-created.png
    ├── subnets.png
    ├── igw-attached.png
    ├── route-table-public.png
    ├── route-table-private.png
    ├── security-groups.png
    ├── ec2-bastion.png
    ├── ec2-private.png
    ├── ssh-connection.png
    ├── nginx-public.png
    └── nginx-private.png

💼 Ideal For

✅ DevOps Engineers ✅ Cloud Enthusiasts ✅ AWS Certification Prep ✅ Portfolio & Resume Boost ✅ Free-Tier AWS Labs

📜 License

MIT License © 2025 Mahesh Shukla

About

Build a secure AWS VPC with Bastion Host and Private EC2 — full hands-on networking project under AWS Free Tier, including NGINX setup, SSH tunneling, and cleanup guide.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published