AWS CLI Quick Guide
This document will give you quick example commands that you can copy/paste and modify for your own use. This shoud get you up and running with the AWS CLI quickly so that you can start automating tasks and saving yourself time as fast as possible.
If you want to install the AWS CLI, checkout our AWS CLI - Install and Setup Guide.
If you need a different region than the one that you have configured, you can append the “–region” option to most commands.
aws ec2 describe-instances --output table --region us-west-1
EC2 Instances
Describe instances:
aws ec2 describe-instances
Filter matching instances:
aws ec2 describe-instances --filters 'Name=tag:Name,Values=dev-lab-server-23b-*'
Start/stop/reboot instances:
aws ec2 start-instances --instance-ids i-0b22a22eec53b1234
aws ec2 stop-instances --instance-ids i-0b22a22eec53b1234
aws ec2 reboot-instances --instance-ids i-0b22a22eec53b1234
Terminate an instance ( remove –dry-run to actually do it ):
aws ec2 terminate-instances --dry-run --instance-ids i-0b22a22eec53b1234
EC2 Volumes
Describe volumes:
aws ec2 describe-volumes
Attach a volume to an instance:
aws ec2 attach-volume --volume-id vol-1d5cf8dd --instance-id i-0b22a22eec53b1234 --device /dev/sde
Run an instance:
aws ec2 run-instances --dry-run --image-id ami-08111123 --count 1 --instance-type t2.micro --key-name Key1 --security-groups sg1
EC2 Images
Create an image:
aws ec2 create-image --instance-id i-0b22a22eec53b1234 --name "Test AMI" --description "my testing AMI"
Describe an image:
aws ec2 describe-images --image-ids ami-2d574123
Deregister an image and delete a snapshot:
aws ec2 deregister-image --image-id ami-2d574123 && aws ec2 delete-snapshot --snapshot-id snap-4e665123
Delete a snapshot:
aws ec2 delete-snapshot --snapshot-id snap-4e665123
EC2 Key Pairs
Describe key pairs:
aws ec2 describe-key-pairs
Create a key pair:
aws ec2 create-key-pair --key-name Key1
Delete a key pair:
aws ec2 delete-key-pair --key-name Key2
EC2 Security Groups
Create a security group:
aws ec2 create-security-group --group-name my-sg1 --description "A security group I created"
EC2 Tags
Tag a resource:
aws ec2 create-tags --resources i-ddddbb12 --tags Key=Office,Value=NYC1
More
Get console output:
aws ec2 get-console-output --instance-id i-0b22a22eec53b1234
Monitor instance:
aws ec2 monitor-instances --instance-ids i-0b22a22eec53b1234
Unmonitor an instance:
aws ec2 unmonitor-instances --instance-ids i-0b22a22eec53b1234
S3 Storage
Use the make bucket command to create a bucket:
aws s3 mb s3://mybucket1
Use the remove bucket command to delete a bucket:
aws s3 rb s3://mybucket1
List S3 Buckets:
aws s3 ls
Recursively list objects in a bucket:
aws s3 ls s3://mybucket1 --recursive
Find total size of all ojbects inside a givine S3 bucket:
aws s3 ls s3://mybucket1 --recursive --human-readable --summarize
Copy / upload file to a bucket:
aws s3 cp file.txt s3://mybucket1
Copy / upload file to a bucket using full path:
aws s3 cp /data/sub1/file.txt s3://mybucket1
Download file from bucket to a specified local directory:
aws s3 cp s3://mybucket1/file.txt /my_data/dir1
Download file from bucket and specify destination file name:
aws s3 cp s3://mybucket1/file.txt file_version2.txt
Move a file to a bucket:
aws s3 mv file.txt s3://mybucket1