Stop 05 · Compute With Amazon EC2Topics · 1/9

What Is Amazon EC2

Part of the AWS Roadmap

In short

A virtual machine is the most basic thing you can rent: a whole computer, minus the box. Almost every other compute service is built on top of it, so this is where you start.

Amazon EC2 rents virtual machines, called instances, that you can start in minutes, resize and stop when you are done. You choose the operating system, size, network and storage, and you manage everything from the OS up.

The blob character waves from one window of a building full of identical rooms.

Think of it like this

Rooms in a PG building

One big building, many rooms. Each room has its own lock, bed and light switch, and you can't wander into your neighbour's. The building is a physical server. Each room is a VM, and you're king of your room.

Watch it happen

One physical host, many VMs

Physical server
Hypervisor
VM: Ubuntu
Your web app
VM: Windows
Another app
VM: Amazon Linux
Another customer

1/4A real machine in a data centre with lots of CPU cores and RAM.

The big ideas

What you need to know

A full computer

You pick the OS image, CPU, RAM and disk. You get root or admin access and install anything.

Images are templates

An image (AMI on AWS) is a snapshot of a disk with an OS. Every VM boots from one.

You maintain it

OS patches, security updates, monitoring agents and backups of the VM are your job.

Pay while it runs

A stopped VM stops compute charges, but its attached disks still cost money until deleted.

See it in code

Walk through the code

bash
1aws ec2 run-instances \2  --image-id resolve:ssm:/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64 \3  --instance-type t3.micro \4  --key-name my-key \5  --security-group-ids sg-0123456789abcdef0 \6  --tag-specifications 'ResourceType=instance,Tags=[{Key=env,Value=dev}]'7 8aws ec2 terminate-instances --instance-ids i-0abc123def4567890

1/4Pick the image. The resolve:ssm trick fetches the current AMI ID for you.

The SSM path always resolves to the latest Amazon Linux 2023 image, so you don't copy AMI IDs that change by region.

Save yourself the pain

Common mistakes

Oops

Stopping a VM and assuming the bill is now zero.

Do this instead

Stopped VMs still pay for attached disks and any reserved public IPs. Terminate what you don't need.

Oops

Treating a VM like a pet you fix by hand forever.

Do this instead

Script its setup (user data, Ansible, an image) so you can rebuild a fresh one in minutes.

Your mission

Launch, log in, tear down

~30 min

Quick check

You stop an EC2 instance for the weekend. What do you still pay for?

Go deeper

  1. 1Read the EC2 overview page and list what you choose when launching an instance.
  2. 2Explain why stopping an instance stops compute charges but not EBS storage charges.
  3. 3Note what EC2 leaves to you compared with a managed service like Lambda.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge