AWS EC2 Tutorial: Getting Started with Amazon EC2

Amazon Elastic Compute Cloud (EC2) is one of the most widely used AWS services. It lets you run virtual servers in the cloud on demand. This tutorial walks you through the core concepts and practical steps to launch and manage your first EC2 instance.

1. What is Amazon EC2?

Amazon EC2 (Elastic Compute Cloud) provides resizable compute capacity in the cloud. Instead of buying and maintaining physical servers, you rent virtual machines (called instances) and pay only for what you use.

2. Key Concepts

TermDescription
AMI (Amazon Machine Image)A pre-configured template for your instance (OS + software).
Instance TypeDefines the CPU, memory, and storage (e.g., t2.micro, m5.large).
Key PairSSH key used to securely connect to Linux instances.
Security GroupA virtual firewall controlling inbound/outbound traffic.
Elastic IPA static public IP address you can attach to an instance.
EBS VolumePersistent block storage attached to an EC2 instance.
Region / AZPhysical data center location. AZ = Availability Zone within a region.

3. Instance Types

EC2 instances are grouped into families based on use case:

FamilyUse CaseExample
General PurposeBalanced CPU/memory for most workloadst3.micro, m6i.large
Compute OptimizedHigh CPU-intensive workloadsc6i.xlarge
Memory OptimizedLarge in-memory datasets (databases, caches)r6i.2xlarge
Storage OptimizedHigh I/O operations (NoSQL databases)i3.large
Accelerated ComputingGPU/ML workloadsp3.2xlarge, g4dn.xlarge

Tip: For testing or the AWS Free Tier, use t2.micro or t3.micro (750 hours/month free).

4. How to Launch an EC2 Instance

Step 1: Sign in to the AWS Console

Go to console.aws.amazon.com/ec2 and click Launch Instance.

Step 2: Choose an AMI

Select an operating system. For a LAMP stack, choose Amazon Linux 2023 or Ubuntu 24.04 LTS.

Step 3: Choose an Instance Type

Select t2.micro (Free Tier eligible) for testing.

Step 4: Configure Key Pair

Create or select an existing key pair (.pem file). Download it — you'll need it to SSH into the instance.

Step 5: Configure Security Group

Allow at minimum:

Step 6: Launch

Click Launch Instance. Your instance will be running in 1–2 minutes.

5. Connecting to Your Instance

Linux / macOS (SSH)

chmod 400 your-key.pem ssh -i "your-key.pem" ec2-user@your-public-ip

For Ubuntu AMIs, use ubuntu instead of ec2-user:

ssh -i "your-key.pem" ubuntu@your-public-ip

Windows (PuTTY)

Convert your .pem key to .ppk using PuTTYgen, then connect via PuTTY using your instance's public IP.

AWS Console (EC2 Instance Connect)

From the EC2 dashboard, select your instance → click Connect → use the browser-based terminal.

6. Security Groups

Security groups act as a virtual firewall. Rules are stateful — allowing inbound traffic also allows the response.

Rule TypePortSourceUse Case
SSH22My IPAdmin access
HTTP800.0.0.0/0Public website
HTTPS4430.0.0.0/0Secure website
MySQL/Aurora3306Security group IDDB from app servers only

7. Next Steps