EC2

Table of Contents
What is Amazon EC2 #
An Amazon EC2 instance is a virtual server in the AWS Cloud. When you launch an EC2 instance, the instance type that you specify determines the hardware available to your instance. Each instance type offers a different balance of compute, memory, network, and storage resources.
EC2 sizing and configuration options #
- Operating System (OS) - Linux, Windows, Mac OS
- How much compute power & CPU cores
- How much RAM
- How much storage space
- Network-attached (EBS & EFS)
- Hardware (EC2 Instance Store)
- Network card: speed of the card, Public IP address
- Firewall rules: security group
- Bootstrap script (configure at first launch): EC2 User Data
Amazon EC2 Instance Types #
More info: EC2 Instance Types, EC2Instances.info
- General Purpose (M, T) - General
- Compute Optimized (C) - Compute bound applications that benefit from thigh performance processors
- Memory Optimized (R, X) - Optimized to deliver fast performance for workloads that process large data sets in memory (i.e. ElastiCache)
- Accelerated Computing (P, G, Trn, Inf, DL, F, VT1) - Calculations, graphics processing or data pattern matching
- Storage Optimized (I, Dx, H1) - High, sequential read and write access to very large data sets on local storage. Low-latency, random I/O operations per second (IOPS)
- HPC Optimized (Hpc) - High Performance Computing - complex simulations and deep learning workloads
Instance type naming conventions #
More info: Amazon EC2 Instance type naming conventions
Example #
More info: Amazon EC2 Instance type naming conventions
Series | Options |
---|---|
- C – Compute optimized - Hpc – High performance computing - I – Storage optimized - M – General purpose - P – GPU accelerated - R – Memory optimized | - a – AMD processors - i – Intel processors - b – Block storage optimization - d – Instance store volumes - e – Extra storage (for storage optimized instance types), extra memory (for memory optimized instance types), or extra GPU memory (for accelerated computing instance types). - n – Network and EBS optimized - q – Qualcomm inference accelerators - z – High CPU frequency |
Launching EC2 instance #
EC2 > Launch Instance
- Name and Tags
- AMI
- Instance Type (t3.micro,t3.large,etc.)
- Key Pair
- Network Settings (Security Group)
- Storage
- Advanced Settings
- Domain Join
- IAM Instance Profile
- Hostname type
- Instance auto-recovery
- Shutdown behavior
- Termination protection
- Placement group
- Purchasing option
- None
- Capacity Blocks
- Spot Instances
- Capacity reservation
- User data
Example user data #
User data is only bootstrap script and only starts once during the machine creation.
#!/bin/bash
# Use this for your user data (script from top to bottom)
# install httpd (Linux 2 version)
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
echo "<h1>Hello World from $(hostname -f)</h1>" > /var/www/html/index.html
Connecting to EC2 from Windows Terminal #
ssh -i .\.ssh\id_rsa_aws25 ec2-user@ec2-3-95-191-175.compute-1.amazonaws.com
EC2 Instances Purchasing options #
- On-Demand instances - short workload, predictable pricing, pay by second
- Pay for what used
- Linux or Windows - billing per second after the first minute
- All other operating systems - billing per hour
- Highest cost but no upfront payment
- No long-term commitment
- Recommended for short-term and un-interrupted workloads
- Pay for what used
- Reserved (1 & 3 years)
- Up to 72% discount compared to On-demand
- You reserve a specific instance attributes (Instance Type, Region, Tenancy, OS)
- Reserved Instances - long workloads
- Payment options - No upfront, Partial Upfront, All Upfront
- Scope: Regional or Zonal
- Recommended for steady-state usage applications (think database)
- Can be bought and sold in the Reserved Instance Market place
- Convertible Reserved Instances - long workload with flexible instances
- Can change the EC2 instance type, instance family, OS, scope and tenancy
- Up to 66% discount
- Saving plans (1 & 3 years) - commitment to an amount of usage, long workloads
- Get discount based on long-term usage
- Commit to a certain type of usage ($10/hour for 1 or 3 years)
- Usage beyond EC2 Savings Plans is billed at the On-Demand price
- Locked to a specific instance family & AWS region
- Flexible across
- Instance Size (e.g. m5.xlarge, m5.2xlarge)
- OS (e.g. Linux, Windows)
- Tenancy (Host, Dedicated, Default)
- Spot Instances - short workloads, cheap, can lose instances
- Up to 90% discount
- Instances can be “lost” at any point if max price is less than current spot price
- Recommended for workloads that are resilient to failure
- Batch jobs
- Data analysis
- Image processing
- Dedicated Hosts - book an entire physical server, control instance placement
- A physical server with EC2 instance capacity fully dedicated to your use
- Recommended for for companies with strong compliance requirements OR server-bound software licenses (per-socket, per-core)
- Purchasing Options:
- On-demand
- Reserved
- Most expensive option
- Dedicated Instances - no other customers will share your hardware
- Instances run on a dedicated hardware
- May share hardware with other instances in the same account
- No control over instance placement
Dedicated Host vs Dedicated Instance: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/dedicated-instance.html
- Capacity Reservations - reserve capacity in a specific AZ for any duration
» Sources « #
- EC2 Instance Types
- Amazon EC2 Instance type naming conventions
- EC2Instances.info
- Dedicated Host vs Dedicated Instance:
Full YouTube Rahul’s AWS Course: https://www.youtube.com/playlist?list=PL7iMyoQPMtAN4xl6oWzafqJebfay7K8KP
» References « #
» Table of contents (CLF-C02) « #
» Disclaimer « #
Disclaimer: Content for educational purposes only, no rights reserved.
Most of the content in this series is coming from Stephane Maarek’s Ultimate AWS Certified Cloud Practitioner CLF-C02 2025 course on Udemy.
I highly encourage you to take the Stephane’s courses as they are awesome and really help understanding the subject.
More about Stephane Maarek:
This article is just a summary and has been published to help me learning and passing the practitioner exam.