Stop 05 · Compute With Amazon EC2Topics · 2/9

Launching an EC2 Instance

Part of the AWS Roadmap

In short

Launching your first EC2 instance is the "hello world" of AWS. In a few minutes you get a real Linux server in a Mumbai data centre, and every choice in the launch wizard teaches you a core AWS concept.

Launching an instance means choosing an AMI, an instance type, a key pair, network settings, security groups and storage. Once it is running you can connect with SSH, EC2 Instance Connect or Systems Manager Session Manager.

The jaadu collects a car key from a rental counter and walks towards a row of different-sized cars parked in a bright lot.

Think of it like this

Booking a self-drive car

You pick the model (instance type), a car with your favourite music already loaded (AMI), the parking zone (subnet), who may open it (security group), the boot size (EBS volume) and you collect the key (key pair). Then you drive, and pay by the hour.

Watch it happen

The launch wizard, decision by decision

AMI
Instance type
Key pair
Network & SG
Storage

1/5Choose the operating system image, for example Amazon Linux 2023 or Ubuntu Server.

The big ideas

What you need to know

Instance states

pending, running, stopping, stopped and terminated. You pay for compute only while it is running, but EBS storage is billed even when stopped.

Terminate means gone

Terminating deletes the instance and, by default, its root volume. Stop if you want to come back later.

Public IPs change

An automatic public IPv4 address changes when you stop and start. Use an Elastic IP or a load balancer for a fixed address.

Tag everything

A Name tag and an owner tag make the console readable and cost reports useful.

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-default-x86_64 \3  --instance-type t3.micro \4  --key-name riya-mumbai \5  --security-group-ids sg-0123456789abcdef0 \6  --subnet-id subnet-0123456789abcdef0 \7  --associate-public-ip-address \8  --metadata-options HttpTokens=required \9  --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=web-1},{Key=owner,Value=riya}]' \10  --region ap-south-1 \11  --query "Instances[0].InstanceId" --output text

1/5resolve:ssm looks up the latest Amazon Linux 2023 AMI ID, so you never hard-code an outdated one.

Launching from the CLI. Replace the security group, subnet and key pair with your own.

Save yourself the pain

Common mistakes

Oops

Opening SSH (port 22) to 0.0.0.0/0 so it 'just works'.

Do this instead

Allow port 22 only from your own IP, or use Session Manager and open no inbound port at all.

Oops

Stopping an instance and assuming the bill drops to zero.

Do this instead

Stopped instances still pay for their EBS volumes and any Elastic IPs. Terminate lab instances when done.

Your mission

Launch, look, terminate

~30 min

Quick check

You stop an EC2 instance for a week. What are you still paying for?

Go deeper

  1. 1Launch a small Amazon Linux instance, connect to it and run a few Linux commands.
  2. 2Stop, start and terminate it, and note how the public IP changes after a stop and start.
  3. 3Set a reminder to terminate every lab instance at the end of the session.

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