Galle, LK--:--5/6 sites live

AWS EC2 Instances, EBS Volumes & Security Groups

පිටුව 11: අපේ පළමු Cloud Server එක හදමු - AWS EC2, EBS සහ Security Groups

AWS EC2 Instance වර්ග (t2.medium), Hard disk (EBS) සයිස් කිරීම, සහ Security Group හරහා Port 8080 විවෘත කරන හැටි.

12 Sept 20264 min readSelf Guide · Stage 11#EC2#EBS#SRE Labs

Lab 11 of 20 · EC2 & Firewalls · 5 hands-on activities · bilingual (English + සිංහල)

පිටුව 11: අපේ පළමු Cloud Server එක හදමු - AWS EC2, EBS සහ Security Groups

AWS EC2 Instance වර්ග (t2.medium), Hard disk (EBS) සයිස් කිරීම, සහ Security Group හරහා Port 8080 විවෘත කරන හැටි.

💡 සරල සිංහලෙන්: AWS EC2 Server එකක් හදනකොට වැදගත් කරුණු 3

1. Instance Size (t2.medium): Micro දැම්මොත් Jenkins සහ Docker වලට RAM එක මදිවෙලා Crash වෙනවා. ඒ නිසා අවම වශයෙන් 4GB RAM තියෙන t2.medium තෝරගන්න.

2. Hard Disk (EBS 30GB): Default එන්නේ 8GB. හැබැයි Jenkins Build Jobs කරනකොට ඒක ඉක්මනින් පිරෙනවා. ඒ නිසා 28GB-30GB අතර volume එකක් ගන්න.

3. Security Group (Port 8080 Open කිරීම): Server එක හැදුවට Browser එකෙන් යන්න බෑ, මොකද AWS එකෙන් ඔක්කොම වහලා තියෙන්නේ. Inbound Rules වලට ගිහින් Port 8080 Open කරන්නම ඕන!

Architectural Foundation & Systems Diagram

AWS EC2 (Elastic Compute Cloud) provides scalable virtual servers in the cloud. You attach virtual disks (EBS) and define stateful virtual firewalls (Security Groups).

  • 💻 EC2 Sizing (t2.medium) — For Jenkins and Docker builds, use at least t2.medium (2 vCPUs, 4GB RAM). Micro instances crash under Java JVM build memory pressure.

  • 💽 EBS Storage (30GB) — Elastic Block Store (EBS) acts as the virtual SSD. Provision at least 28-30 GB to prevent Jenkins build workspace disk exhaustion.

  • 🛡️ Security Groups (Stateful Firewalls) — Virtual firewalls controlling inbound and outbound traffic. You MUST add an Inbound Rule for Custom TCP Port 8080 from 0.0.0.0/0 to access web dashboards!

Step-by-step practical lab

Step 01: Lock Down SSH Private Key Permissions

සිංහලෙන් — SSH Private Key එකේ permissions ආරක්ෂිතව (0400) සකසමු.

Restrict file permissions so only the owner can read the private key, satisfying OpenSSH security requirements.

ExampleShell
chmod 400 ~/.ssh/my-key.pem
  • 400 : Owner Read Only: අනෙක් කිසිදු පරිශීලකයෙකුට හෝ process එකකට කියවිය නොහැක.

Expected output

Output
-r-------- 1 sre-engineer devops 1675 Sep 16 11:00 ~/.ssh/my-key.pem

SRE Tip: If key permissions are 0644 or higher, SSH will reject connection with 'WARNING: UNPROTECTED PRIVATE KEY FILE!'.

Step 02: Test Secure Shell Connection to EC2

සිංහලෙන් — AWS EC2 Server එකකට SSH Key එකක් භාවිතයෙන් සම්බන්ධ වීම.

Connect securely to an AWS EC2 instance via SSH using a private PEM key pair.

ExampleShell
ssh -i ~/.ssh/my-key.pem ec2-user@172.31.18.42
  • -i : Identity file: Authentication සඳහා භාවිත කරන private key එක දක්වයි.

Expected output

Output
Authenticated with key ~/.ssh/my-key.pem.
Amazon Linux 2023 AMI 2023.4.2026
[ec2-user@ip-172-31-18-42 ~]$

SRE Tip: Always use Bastion Hosts or AWS Systems Manager (SSM) Session Manager to access instances in private subnets without exposing Port 22 to the public internet.

Hands-on practice activities

Work through these yourself — tick them off as you go.

  • Activity 51: Check EBS Disk Capacity and Free Space (Drill) — Verify attached EBS volume storage and ensure root partition has over 20GB free space.
  • Activity 52: Check Active Listening Web Ports (Drill) — Verify that port 8080 is actively listening on all local interfaces (0.0.0.0:8080).
  • Activity 53: Add Security Group Inbound Rule for 8080 (Checkpoint) — In AWS Console: EC2 > Security Groups > Edit Inbound Rules > Add Rule: Type=Custom TCP, Port=8080, Source=0.0.0.0/0.
  • Activity 54: Secure SSH Keypair Permissions (Checkpoint) — Execute 'chmod 400 your-key.pem' before attempting SSH connection to your EC2 instance.
  • Activity 55: Security Group Stateful Property Quiz (Quiz) — If an inbound packet is permitted by an AWS Security Group, is outbound response traffic automatically allowed? Answer: Yes, Security Groups are stateful.

Keep going: ← Lab 10 · Lab 12 → · Track your progress in the Self Guide

ExerciseKnowledge check

What AWS service functions as a stateful virtual firewall controlling traffic at the instance level? / EC2 Instance මට්ටමේ virtual firewall එක කුමක්ද?

Finished this one?

Part of Self Guide · Stage 11: SRE Labs II — cloud, containers and delivery. Progress is saved in this browser.

Guide