AWS CLI EC2 Cheat Sheet

AWS CLI EC2 commands for instances, AMIs, key pairs, VPC networking, security groups, EBS volumes, and snapshots.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## EC2 Instances
Describe instances
aws ec2 describe-instances

# List EC2 instances and their attributes.

Describe instances with query
aws ec2 describe-instances --query 'Reservations[].Instances[].{Id:InstanceId,State:State.Name,Type:InstanceType,Name:Tags[?Key==`Name`]|[0].Value,PrivateIp:PrivateIpAddress}' --output table

# Return a compact list of instance details.

Launch an instance
aws ec2 run-instances --image-id ami-0123456789abcdef0 --instance-type t3.micro --subnet-id subnet-0123456789abcdef0 --security-group-ids sg-0123456789abcdef0 --count 1

# Start one or more EC2 instances.

Start stopped instances
aws ec2 start-instances --instance-ids i-0123456789abcdef0

# Power on one or more stopped instances.

Stop running instances
aws ec2 stop-instances --instance-ids i-0123456789abcdef0

# Gracefully stop one or more instances.

Reboot instances
aws ec2 reboot-instances --instance-ids i-0123456789abcdef0

# Perform an OS-level reboot.

Terminate instances
aws ec2 terminate-instances --instance-ids i-0123456789abcdef0

# Permanently delete one or more instances.

Wait until instance is running
aws ec2 wait instance-running --instance-ids i-0123456789abcdef0

# Poll until an instance reaches the running state.

## AMIs and Key Pairs
Describe AMIs
aws ec2 describe-images --owners self amazon

# List AMIs visible to the account.

Create an AMI from an instance
aws ec2 create-image --instance-id i-0123456789abcdef0 --name web-ami-2026-03-05

# Create an image snapshot from an EC2 instance.

List key pairs
aws ec2 describe-key-pairs

# Show EC2 key pairs in the account.

Create a key pair
aws ec2 create-key-pair --key-name my-key --query 'KeyMaterial' --output text > my-key.pem

# Generate a new EC2 key pair and save the private key.

Delete a key pair
aws ec2 delete-key-pair --key-name my-key

# Remove a key pair from the account.

## VPC, Subnets, and Security Groups
Describe VPCs
aws ec2 describe-vpcs

# List VPCs in the account.

Describe subnets
aws ec2 describe-subnets

# List subnets and their attributes.

Describe security groups
aws ec2 describe-security-groups

# List security groups and their rules.

Add inbound security group rule
aws ec2 authorize-security-group-ingress --group-id sg-0123456789abcdef0 --protocol tcp --port 443 --cidr 0.0.0.0/0

# Allow inbound TCP 443 from a CIDR block.

Remove inbound security group rule
aws ec2 revoke-security-group-ingress --group-id sg-0123456789abcdef0 --protocol tcp --port 443 --cidr 0.0.0.0/0

# Delete an inbound rule from a security group.

Tag EC2 resources
aws ec2 create-tags --resources i-0123456789abcdef0 vol-0123456789abcdef0 --tags Key=Env,Value=prod Key=App,Value=api

# Apply tags to one or more EC2 resources.

## EBS Volumes and Snapshots
Describe EBS volumes
aws ec2 describe-volumes

# List attached and unattached EBS volumes.

Create an EBS volume
aws ec2 create-volume --availability-zone us-west-2a --size 50 --volume-type gp3

# Create a new volume in a specific AZ.

Attach a volume
aws ec2 attach-volume --volume-id vol-0123456789abcdef0 --instance-id i-0123456789abcdef0 --device /dev/xvdf

# Attach an existing EBS volume to an instance.

Create a snapshot
aws ec2 create-snapshot --volume-id vol-0123456789abcdef0 --description 'nightly backup'

# Snapshot an EBS volume.

Describe snapshots
aws ec2 describe-snapshots --owner-ids self

# List snapshots visible to the account.

Delete a snapshot
aws ec2 delete-snapshot --snapshot-id snap-0123456789abcdef0

# Remove a no-longer-needed snapshot.

Recommended next

No recommendations yet.