skip to content

Search

Syspirit
EN

AWS EC2

Choose, buy and run your EC2 instances: types, purchasing options, states, Auto Scaling and load balancers!

AWS
Published on
Karl Certa

Amazon EC2 (Elastic Compute Cloud) is the AWS virtual machine service: you pick an instance type, an image and a purchasing option, and AWS provides the capacity in the requested Availability Zone (AZ).

🏷️ Reading an instance type name

An instance type name reads in four parts: series, generation, options, then size after the dot.

📌 Part📊 Example m7g.large💡 Meaning
🔤 SeriesmWorkload family (here general purpose)
🔢 Generation7The higher the number, the newer the hardware
⚙️ OptionsgAWS Graviton processor (Arm)
📏 SizelargeNumber of virtual processors (vCPU) and memory (metal for bare metal)

Main series

📌 Series🎯 Focus💼 Typical use cases
TBurstable: baseline CPU performance, with burstsSmall web servers, dev/test, lightly loaded workloads
MBalanced general purposeApplication servers, backends
CCompute optimizedIntensive compute, batch, encoding
R / XMemory optimized / memory intensiveIn-memory databases, caches, analytics
I / DStorage optimized / dense storageNoSQL databases, heavy local disk I/O
P / GGPU acceleratedMachine learning training, graphics rendering

Common options in the name

📌 Letter💡 Meaning
aAMD processor
gAWS Graviton processor (Arm): beware, it needs an arm64 AMI
iIntel processor
dInstance Store volumes (local disks) included

💰 Purchasing options

Discounts are stated “up to” compared with On-Demand pricing; the actual rate depends on type, Region, term and payment.

📌 Purchasing option🔒 Commitment💰 Max discount🎯 Use case
On-DemandNone, billed per second (60 s minimum)NoneUnpredictable load, tests, short needs
Savings Plans1 or 3 years, amount in $/hourUp to 72%Stable baseline load, recommended by AWS over RIs
Reserved Instances (RI)1 or 3 years, fixed instance attributesUp to 72%Stable 24/7 load on a known type
SpotNone, instance reclaimed by AWS with a 2 min noticeUp to 90%Batch, continuous integration, rendering, any job that tolerates interruption
Dedicated InstanceNoneDepends on the option chosenPhysical hardware dedicated to a single account
Dedicated HostHourly or 1 / 3 year reservationReservation up to 70%BYOL (Bring Your Own License) per socket or core
Capacity ReservationNone for immediate useNoneGuarantee capacity in an AZ (event, disaster recovery plan)

Savings Plans: which one

📌 Type🌍 Scope💰 Max discount
Compute Savings PlansEC2 across families and Regions, Fargate, LambdaUp to 66%
EC2 Instance Savings PlansOne instance family in one RegionUp to 72%

Reserved Instances: variants

📌 Criterion📊 Options💡 Consequence
🔒 ClassStandard / ConvertibleStandard: best discount, can only be modified. Convertible: exchangeable for other attributes, lower discount
💳 PaymentAll / Partial / No UpfrontThe more you pay upfront, the bigger the discount
📍 ScopeRegional / ZonalOnly a zonal RI reserves capacity in an AZ
⏳ TermNon-cancellable, no automatic renewalDue until the end even if the instance is terminated; then On-Demand rate

Spot, Dedicated and Capacity Reservation: rules to remember

📌 Item📊 Rule💡 Why it matters
⚡ Spot interruptionMostly when EC2 needs the capacity back, or if the Spot price exceeds your max priceSetting a max price makes interruptions more frequent
⏱️ Spot notice2 minutes before stop or termination (via EventBridge and metadata)No 2 min warning if the chosen behavior is hibernation
🖥️ Dedicated HostBilled per host, socket / core visibility, host affinityRequired for licenses bound to physical hardware
📦 Capacity ReservationBilled at the On-Demand rate, whether an instance runs in it or notNo discount of its own: combine with Savings Plans or regional RIs

🔄 Instance states and billing

📌 State💰 Instance billed💡 Meaning
pendingNoStarting up
runningYesInstance in service, even when idle
stoppingNo (yes when hibernating)Stopping
stoppedNoStopped, can be started; EBS (Elastic Block Store) volumes are still billed
shutting-downNoTermination in progress
terminatedNoPermanently deleted

Stop, hibernate, terminate: what is kept

📌 Item⏸️ Stop💤 Hibernate🗑️ Terminate
🖥️ Physical hostUsually changesUsually changesNone
🧮 RAMErasedSaved to the EBS root volumeErased
💽 EBS root volumeKeptKeptDeleted by default
💾 Other EBS volumesKeptKeptKept by default (DeleteOnTermination)
⚡ Instance StoreData erasedData erasedData erased
🔒 Private IPv4KeptKeptNone
🌐 Public IPv4New one at startNew one at startNone
📍 Elastic IPStays associatedStays associatedDisassociated, still allocated to the account

Hibernation prerequisites

📌 Prerequisite📊 Value
⚙️ EnablingAt launch only, not possible on an existing instance
🧮 RAMLess than 150 GiB (Linux), 16 GiB max (Windows)
💽 Root volumeEncrypted EBS, large enough to hold the RAM
⏳ Duration60 days maximum in hibernated state
🚫 Not supportedInstances in an Auto Scaling Group, bare metal

🖼️ AMI, User Data and metadata

📌 Item📊 Rule💡 Consequence
🖼️ AMI (Amazon Machine Image)Boot image specific to a Region, an OS and an architectureTo launch elsewhere, copy the AMI to the target Region
📜 User DataScript or cloud-init directives, run as root at first bootDoes not run again on reboot without dedicated configuration
📏 User Data size16 KB before base64 encodingHard limit, keep the script short
📄 User Data logs/var/log/cloud-init-output.logFirst place to look when bootstrap fails
🔑 IMDSv2 (Instance Metadata Service v2)Metadata on 169.254.169.254, token obtained with a PUT requestRequiring IMDSv2 blocks calls without a token (IMDSv1)
TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` \
&& curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/instance-id

📍 Placement groups

📌 Strategy🗺️ Scope📊 Limit🎯 Use case
ClusterSingle AZNo T or Mac1; same type recommendedHPC (High Performance Computing), low latency between nodes
SpreadSeveral AZs, each instance on a distinct rack7 running instances per AZA few critical instances to keep apart
PartitionSeveral AZs, each partition on its own racks7 partitions per AZHDFS, HBase, Cassandra

Spread isolates each instance, hence the low limit. Partition isolates groups: two instances in the same partition can fail together, but a rack failure only hits one partition. An AZ outage takes down an entire Cluster placement group.

🌐 Elastic IP

📌 Item📊 Value💡 Consequence
📍 ScopeOne Region, cannot be movedAn Elastic IP (EIP) from eu-west-3 cannot be used in eu-central-1
🔢 Default quota5 Elastic IPs per RegionAWS advises keeping them for failover, DNS for everything else

📈 Auto Scaling Group (ASG)

📌 Item📊 Role
📄 Launch TemplateInstance template: AMI, type, Security Groups, User Data, role
🔢 Min / Desired / MaxThe group never goes below min, never above max, and aims for desired
🗺️ Multi-AZInstances balanced evenly across the chosen AZs
❤️ Health checksEC2 status checks by default, ELB (Elastic Load Balancing) health checks optional; unhealthy instance replaced
🔗 Load balancerInstances registered and deregistered automatically
🪝 Lifecycle hooksPause at launch or termination (1 h by default) to install software or collect logs

Scaling policies

📌 Policy⚙️ Principle🎯 When to use it
Target trackingKeeps a metric at a target (average CPU at 50%)Choice recommended by AWS in most cases
Step scalingStepped adjustments based on the size of the alarm breachGraduated response to CloudWatch thresholds
Simple scalingOne adjustment per alarm, then cooldown (300 s by default)Discouraged by AWS, prefer target tracking or step
ScheduledChanges min / desired / max at a set time (cron expression, time zone)Predictable load: office opening hours, end of week
PredictiveForecasts load from history and launches capacity ahead of timeCyclical traffic, applications slow to start

⚖️ Choosing a load balancer

📌 Load balancer🧱 Layer📊 Protocols🔀 Cross-zone by default🎯 Use case
ALB (Application Load Balancer)7HTTP, HTTPS, gRPCAlways onWeb applications, routing by path, host or header
NLB (Network Load Balancer)4TCP, UDP, TLSOffExtreme performance, static IP or Elastic IP per AZ
GWLB (Gateway Load Balancer)3 and 4IP (GENEVE, port 6081)OffInserting third-party appliances: firewalls, intrusion detection and prevention

Security Groups (stateful firewall at instance level) are covered in the VPC cheatsheet.

Related posts