HomeBlogAboutPricingContact🌐 中文
Back to HomeAWS
AWS EC2 Complete Tutorial: Instance Types, Pricing, Implementation Guide [2025]

AWS EC2 Complete Tutorial: Instance Types, Pricing, Implementation Guide [2025]

📑 Table of Contents

AWS EC2 Complete Tutorial: Instance Types, Pricing, Implementation Guide [2025]AWS EC2 Complete Tutorial: Instance Types, Pricing, Implementation Guide [2025]

AWS EC2 Complete Tutorial: Instance Types, Pricing, Implementation Guide [2025]

A physical server costs tens of thousands of dollars upfront, requires a place to store it, someone to maintain it, and depreciates over time. AWS EC2 lets you launch a virtual server in 60 seconds for just a few cents per hour. Turn it off when you're done—no charge.

This article will guide you through EC2 from the ground up—what it is, what instance types are available, how pricing works, and step-by-step instructions to create your first EC2 instance.



What is AWS EC2?

💡 Key Takeaway: EC2 (Elastic Compute Cloud) is AWS's core compute service—essentially "cloud virtual servers."

Think of EC2 as renting a computer in the cloud. This computer can:

EC2 vs Traditional Servers

AspectTraditional ServersAWS EC2
Acquisition TimeWeeks (procurement, delivery, setup)Minutes
Upfront CostHigh (buy hardware)Zero (pay as you go)
Spec ChangesDifficult (need hardware swap)Easy (just restart)
MaintenanceAll on youAWS handles hardware layer
ScalabilityLimited by physical hardwareVirtually unlimited
RiskHardware failure = downtimeAutomatically distributed across data centers

Typical EC2 Use Cases



EC2 Instance Types

EC2 has over 600 instance types. Sounds overwhelming, but they're organized into "families," each designed for specific use cases.

Instance Naming Convention

Understanding the naming convention helps you quickly grasp an instance's characteristics:

t3.medium
│ │  │
│ │  └─ Size (nano < micro < small < medium < large < xlarge < 2xlarge...)
│ └──── Generation (higher number = newer)
└────── Family (determines characteristics)

For example, m7i.2xlarge:

General Purpose (T, M Series)

Suitable for most workloads with balanced CPU and memory.

T Series (Burstable)

InstancevCPUMemoryFeaturesUse Cases
t3.micro21 GBFree Tier eligibleTesting, small websites
t3.small22 GBLow-cost entryLight applications
t3.medium24 GBMost popularGeneral websites, dev environments
t3.large28 GBMid-size appsMedium websites, small databases

T Series Feature: Burstable

T series instances run at lower baseline CPU, accumulating "CPU credits." When needed, they can burst to 100% CPU. This design keeps prices lower, perfect for applications with variable loads.

⚠️ Note: If your application consistently needs high CPU, T series may not be suitable as credits will deplete.

M Series (General Purpose)

InstancevCPUMemoryFeaturesUse Cases
m7i.large28 GBLatest generationProduction environments
m7i.xlarge416 GBEnterprise-gradeMedium application servers
m7i.2xlarge832 GBHigh performanceDatabases, app servers

M series doesn't have burstable mechanics—it provides consistent, stable performance for production environments requiring predictable compute.

Compute Optimized (C Series)

Strongest CPU performance, ideal for compute-intensive workloads.

InstancevCPUMemoryUse Cases
c7i.large24 GBBatch processing
c7i.xlarge48 GBScientific computing
c7i.2xlarge816 GBHigh-performance web servers
c7i.4xlarge1632 GBGame servers, video encoding

When to choose C series:

Memory Optimized (R, X Series)

Large memory capacity for memory-intensive applications.

R Series

InstancevCPUMemoryUse Cases
r7i.large216 GBMemory caching
r7i.xlarge432 GBMedium databases
r7i.2xlarge864 GBLarge databases
r7i.4xlarge16128 GBIn-memory analytics

X Series (Extra Large Memory)

InstancevCPUMemoryUse Cases
x2idn.xlarge4128 GBSAP HANA
x2idn.2xlarge8256 GBLarge in-memory databases
x2idn.4xlarge16512 GBExtreme memory applications

When to choose R/X series:

Accelerated Computing (P, G Series)

Equipped with GPUs for machine learning and graphics workloads.

SeriesGPU TypeUse Cases
P5NVIDIA H100Large model training, Generative AI
P4dNVIDIA A100Machine learning training
G5NVIDIA A10GML inference, graphics rendering
Inf2AWS Inferentia2High-performance inference

When to choose P/G series:

Instance Type Selection Guide

Not sure what to choose? Use this decision tree:

What's your application's characteristic?
│
├─ Variable traffic, peak periods → T series (cost-effective)
│
├─ Stable runtime, predictable performance → M series
│
├─ CPU intensive (computing, encoding) → C series
│
├─ Memory intensive (databases, caching) → R series
│
├─ Needs GPU (ML, graphics) → P/G series
│
└─ Unsure → Start with T3/M7i, adjust based on monitoring


EC2 Pricing Models

EC2 costs depend on two factors: instance type and payment method. The same instance can vary by up to 90% in price depending on how you pay.

On-Demand Instances

The simplest payment method: pay by the hour, or by the second (for Linux instances).

Pros:

Cons:

Pricing Examples (US East region):

InstanceHourly PriceMonthly 24/7
t3.micro$0.0104~$7.5
t3.medium$0.0416~$30
m7i.large$0.1008~$73
c7i.xlarge$0.1785~$130

Best for:

Reserved Instances

Commit to 1 or 3 years in exchange for discounts.

Discount Ranges:

TermPaymentDiscount
1 yearAll upfront~40%
1 yearPartial upfront~35%
1 yearNo upfront~30%
3 yearAll upfront~60%
3 yearPartial upfront~55%
3 yearNo upfront~50%

Pros:

Cons:

Best for:

Spot Instances

Use AWS's idle compute capacity with fluctuating prices—save up to 90%. But AWS can reclaim instances at any time (with 2-minute warning).

Price Examples:

InstanceOn-DemandSpotSavings
t3.medium$0.0416/hr~$0.0125/hr70%
m7i.large$0.1008/hr~$0.0403/hr60%
c7i.xlarge$0.1785/hr~$0.0535/hr70%

Pros:

Cons:

Best for:

Savings Plans

More flexible than Reserved Instances. You commit to a fixed hourly spend (e.g., $10/hr), and AWS automatically applies optimal discounts.

Two types of Savings Plans:

TypeFlexibilityDiscount
Compute Savings PlansAcross EC2, Lambda, Fargate~66% (1yr) / ~72% (3yr)
EC2 Instance Savings PlansLimited to specific instance families and regions~72% (1yr) / ~78% (3yr)

Best for:

Pricing Model Comparison

ModelDiscountFlexibilityUse Case
On-Demand0%HighestShort-term, uncertain needs
Reserved30-60%LowStable production
Spot60-90%Medium (can interrupt)Interruptible batch processing
Savings Plans30-72%Medium-HighStable but varying mix

Choosing the wrong EC2 type can cost you several times more

Many enterprises run production on On-Demand without knowing Reserved Instances save 40%. Even more choose wrong instance types, using M series for workloads that only need T series.

Schedule a free bill review and let us find your savings opportunities.



EC2 Setup Tutorial

Here are complete steps to create an EC2 instance in the AWS Console:

Step 1: Log into AWS Console

  1. Go to AWS Console
  2. Log into your AWS account
  3. Search for "EC2" in the top search bar and click to enter EC2 service

Step 2: Launch Instance

  1. Click the orange "Launch Instance" button
  2. Enter an instance name (e.g., my-web-server)

Step 3: Choose AMI

AMI (Amazon Machine Image) is the OS image that determines what system your EC2 comes pre-installed with.

Common AMI Choices:

AMIDescriptionUse Cases
Amazon Linux 2023AWS-optimized LinuxGeneral purpose, recommended
UbuntuMost popular Linux distributionDeveloper familiarity
Windows ServerMicrosoft Windows.NET applications, GUI needs
Red Hat EnterpriseEnterprise LinuxCorporate compliance requirements

Recommendation: If no special requirements, choose Amazon Linux 2023. It's optimized for AWS, free, and comes with AWS CLI pre-installed.

Step 4: Choose Instance Type

Based on the selection guide above, choose an appropriate instance type.

Beginner Recommendations:

Step 5: Configure Key Pair

Key pairs are used for SSH connections to EC2.

  1. Click "Create new key pair"
  2. Enter a name (e.g., my-key)
  3. Choose format:
    • .pem: For Mac/Linux (OpenSSH)
    • .ppk: For Windows (PuTTY)
  4. Click "Create key pair"—file downloads automatically
  5. Important: This file can only be downloaded once—keep it safe

Step 6: Configure Networking

VPC and Subnet

For new accounts, use the default VPC.

For advanced settings: AWS VPC Tutorial

Security Group

Security groups are EC2's firewall, controlling what traffic can enter and exit.

Common Settings:

TypeProtocolPortSourceDescription
SSHTCP22My IPAllow your IP to connect
HTTPTCP800.0.0.0/0Allow everyone to access website
HTTPSTCP4430.0.0.0/0Allow everyone to access website
CustomTCP30000.0.0.0/0Node.js dev server

⚠️ Security Reminder:

Step 7: Configure Storage

EBS (Elastic Block Store) is EC2's disk storage.

Common Settings:

TypeDescriptionUse Cases
gp3General purpose SSD (latest)Most workloads
gp2General purpose SSDLegacy, can upgrade to gp3
io2High-performance SSDDatabases, high IOPS needs
st1Throughput-optimized HDDLarge file sequential reads

Recommendations:

Step 8: Advanced Settings (Optional)

User Data

Enter scripts to run automatically on boot. For example:

#!/bin/bash
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
echo "<h1>Hello from EC2</h1>" > /var/www/html/index.html

This script automatically installs Apache web server.

Step 9: Review and Launch

  1. Review all settings
  2. Click "Launch Instance"
  3. Wait about 1-2 minutes for status to become "Running"

Step 10: Connect to EC2

Linux (SSH):

# Set key permissions
chmod 400 my-key.pem

# Connect (replace IP with your EC2 public IP)
ssh -i my-key.pem [email protected]

Windows (PuTTY):

  1. Open PuTTY
  2. Host Name: [[email protected]](/cdn-cgi/l/email-protection)
  3. Connection > SSH > Auth > Credentials > Private key file: select .ppk file
  4. Click Open

After successful connection, you'll see:

__|  __|_  )
       _|  (     /   Amazon Linux 2023
      ___|\___|___|

[ec2-user@ip-172-31-xx-xx ~]$


EC2 Cost Calculation Examples

Scenario 1: Small Website

Configuration:

Monthly Estimate:

ItemCalculationCost
EC2 (On-Demand)$0.0208 × 730 hr$15.18
EBS$0.08 × 30 GB$2.40
Data Transfer (first 100GB free)0$0.00
Total~$18/month

With Reserved Instance (1 year):

Scenario 2: Medium Application

Configuration:

Monthly Estimate:

ItemCalculationCost
EC2 (On-Demand)$0.1008 × 730 hr × 2$147.17
EBS$0.08 × 100 GB × 2$16.00
ALBFixed fee + LCU~$25.00
Data Transfer$0.09 × 100 GB$9.00
Total~$197/month

With Savings Plans (1 year):

Scenario 3: Batch Processing (Spot)

Configuration:

Monthly Estimate:

ItemCalculationCost
EC2 (Spot, assuming 70% savings)$0.357 × 0.3 × 4 hr × 30 days × 10$128.52
Total~$130/month

With On-Demand:



EC2 Best Practices

Cost Optimization

  1. Choose the right instance type

    • Monitor CPU and memory utilization
    • If CPU consistently below 40%, consider downsizing
    • Use AWS Compute Optimizer for recommendations
  2. Choose the right payment method

    • Baseline load: Reserved / Savings Plans
    • Peak load: On-Demand
    • Interruptible work: Spot
  3. Turn off idle resources

    • Shut down dev environments after hours
    • Use AWS Instance Scheduler for automation
  4. Choose the right region

    • US East (us-east-1) is usually cheapest
    • But consider latency and regulatory requirements

Security

  1. Principle of least privilege

    • Only open necessary ports in security groups
    • Use IAM Roles instead of access keys
  2. Don't use root account

    • Create IAM users for daily operations
    • Enable MFA
  3. Regular updates

    • Enable automatic security updates
    • Regularly check for AMI updates
  4. Use Session Manager

    • No need to open SSH port
    • Complete audit logging

Availability

  1. Deploy across Availability Zones

    • Deploy instances in at least 2 AZs
    • Use Load Balancer to distribute traffic
  2. Use Auto Scaling

    • Automatically add/remove instances based on load
    • Set minimum, maximum, and desired capacity
  3. Backup strategy

    • Regularly create EBS snapshots
    • Consider cross-region backups

Performance

  1. Choose the right EBS type

    • High IOPS needs: io2
    • General purpose: gp3
  2. Use Placement Groups

    • Need low latency: Cluster
    • Need high availability: Spread
  3. Monitor and adjust

    • Set up CloudWatch alarms
    • Regularly review performance metrics


FAQ

What's the difference between EC2 and Lightsail?

Lightsail is a simplified version of EC2, offering fixed-price packages (including compute, storage, transfer). It's ideal for users who don't want to dive deep into AWS. EC2 is more flexible but more complex to configure.

Can EC2 run Docker?

Yes. Install Docker on EC2 and you can run containers. But if you're primarily running containers, consider evaluating ECS or EKS.

What's the difference between Stop and Terminate?

How do I choose a Region?

Consider:

  1. Latency: Choose regions closest to your users
  2. Price: US East is usually cheapest
  3. Services: New services typically launch in US East first
  4. Regulations: Some data must stay in specific countries


Next Steps

EC2 is AWS's most fundamental and important service. Master EC2, and you've mastered core cloud computing concepts.

Recommended Learning Path:

  1. Hands-on: Create a t3.micro, set up a simple website
  2. Storage: Learn to use S3 with EC2
  3. Networking: Deep dive into VPC architecture
  4. Advanced: Auto Scaling, Load Balancer

Need a second opinion on your EC2 architecture?

Choosing the wrong instance type, pricing model, or architecture design can multiply your AWS bill. The CloudSwap team has years of AWS architecture experience, helping hundreds of enterprises optimize their EC2 configurations.

Schedule a free architecture consultation and let us design the optimal EC2 architecture for you.



Further Reading


Need Professional Cloud Advice?

Whether you're evaluating cloud platforms, optimizing existing architecture, or looking for cost-saving solutions, we can help

Book Free Consultation

AWSKubernetesDocker
Previous
AWS vs GCP vs Azure 2025 Complete Comparison: Features, Pricing, Pros & Cons
Next
AWS Complete Guide: Services, Pricing, Certifications, and Resources Explained [2025]