AWS Cheat Sheet is a mini ebook with the most common AWS CLI commands that an administrator may use on a daily basis. AWS CLI Cheat Sheet Sponsors Contact Write for us Feedback.
I have been standing up quite a bit of infrastructure in AWS lately using the AWS CLI. Here are some commands that I found helpful in a cheat sheet format. I'll show you how to create resources, query resources for information and how to update resources. Hopefully this will get you started quickly. The cheat sheet covers the following topics:- A place to quickly lookup commands ( bash, Vim, git, AWS, Docker, Terraform, Ansible, kubectl) Bash; Vim; Git (Includes Pull Request and Forked Repo Syncing steps) AWS; Docker; Terraform; Ansible; Kubernetes (Includes steps for running a simple container) Hacking tool cheat sheet from compass security; A Cloud Guru K8s Cheat Sheet; Simple setup for a COBRA CLI.
- The one-page guide to AWS CLI: usage, examples, links, snippets, and more.
- AWS CLI cheat sheet: Basic AWS command structure: aws command subcommand options and parameters. Command Help: aws service help. Here, I will go over some examples for a few services to give you an idea. AWS S3 (Simple Storage Service): Print a list of all buckets in your AWS account: aws s3 ls.
- Setting up your environment.
- Working with Virtual Private Clouds (VPC).
- Working with Identity and Access Management (IAM).
- Working with Route53.
- Working with Elastic Load Balancers (ELB).
- Working with SSH.
- Working with DHCP.
- Working with Elastic Compute Cloud (EC2).
- Utilizing queries to gather information.
You can preview the AWS CLI cheat sheet by clicking below (hover mouse over upper right corner):
Aws Cli Commands Cheat Sheet 2019
Useful Aws Cli Commands
You can test all these commands with Fedora images which can be launched here: https://getfedora.org/cloud/download/.
Aws Cli Commands Cheat Sheet Pdf
If you have any questions about any of the commands in particular, please drop a comment below and I'll try to help. Much credit goes to Ryan Cook for frontloading a lot of this.
aws_cli_cheat_sheet.txt
Aws Cli Commands Cheat Sheet Printable
# Count total EBS based storage in AWS |
aws ec2 describe-volumes | jq '[.Volumes[].Size] | add' |
# Count total EBS storage with a tag filter |
aws ec2 describe-volumes --filters 'Name=tag:Name,Values=CloudEndure Volume qjenc' | jq '[.Volumes[].Size] | add' |
# Describe instances concisely |
aws ec2 describe-instances | jq '[.Reservations | .[] | .Instances | .[] | {InstanceId: .InstanceId, State: .State, SubnetId: .SubnetId, VpcId: .VpcId, Name: (.Tags[]|select(.Key'Name')|.Value)}]' |
# Wait until $instance_id is running and then immediately stop it again |
aws ec2 wait instance-running --instance-id $instance_id && aws ec2 stop-instances --instance-id $instance_id |
# Get 10th instance in the account |
aws ec2 describe-instances | jq '[.Reservations | .[] | .Instances | .[]] | .[10]' |
# List the private IP addresses of all instances |
aws ec2 describe-instances | jq '[.Reservations | .[] | .Instances | .[] | .PrivateIpAddress] | sort' |
# Do that, but only on non-terminated instances |
aws ec2 describe-instances | jq '[.Reservations | .[] | .Instances | .[] | select(.State.Name!='terminated') | {Name: (.Tags[]|select(.Key'Name')|.Value), PrivateIp: .PrivateIpAddress}]' |
# JQ export to csv command / suffix |
export_csv_suffix='| map([.Name, .PrivateIp] | join(',')) | join('n')' |
# Get all production instances |
instance_ids=$(aws ec2 describe-instances | jq '[.Reservations | .[] | .Instances | .[] | select(.State.Name!='terminated') | select((.Tags[]|select(.Key'Environment')|.Value) 'prod') | {Name: (.Tags[]|select(.Key'Name')|.Value), InstanceId: .InstanceId}]' | jq '.[] | .InstanceId') |
# Add a backup tag to those instances |
echo $instance_ids | sed 's/'//g' | grep i- | parallel --delay 3 aws ec2 create-tags --resources {} --tags Key=Backup,Value=PolicyA |
# Attach multiple new ebs volumes to an instance |
instance_id='i-0d42888191f597bb8' |
volume_size='8' |
for x in {a..h} |
do |
volume_id=$(aws ec2 create-volume --size $volume_size --volume-type gp2 --availability-zone eu-west-1a | jq -r '.VolumeId') |
aws ec2 wait volume-available --volume-ids $volume_id |
aws ec2 attach-volume --volume-id $volume_id --instance-id $instance_id --device /dev/xvd$x |
done |
# Produce a summary of instances |
jq '[.Reservations | .[] | .Instances | .[] | select(.State.Name!='terminated') | {Name: (.Tags[]|select(.Key'Name')|.Value), InstanceId: .InstanceId}]' |
# Check instances for ones which are missing required tags |
instances=$(cat './scripts/prod-instances.json') |
required_tags='['Environment','Backup','Owner','AppName','Name']' |
echo $instances | jq '[.Reservations | .[] | .Instances | .[] | select(.Tags | [.[] | .Key] | contains($required_tags) | not)]' | jq ' |
[.[] | select(.State.Name!='terminated') | select(([.Tags | .[] | .Key]) | contains(['CloudEndure creation time']) | not) | { |
InstanceId: .InstanceId, |
InstanceName: (.Tags | from_entries | .Name), |
MissingTags: (('$required_tags') - ([.Tags | .[] | .Key])) |
}]' |
# Get the 'Live & Tagged' instances |
instances=$(aws ec2 describe-instances) |
live=$(echo $instances | jq '[.Reservations | .[] | .Instances | .[] | select(.Tags | [.[] | .Key] | contains($required_tags))]') |
# Enable termination protection from a list of instances stored in $list |
echo $live | jq -r '.[] | .InstanceId' | while read id |
do |
echo 'Enabling termination proection on machine: $id' |
aws ec2 modify-instance-attribute --disable-api-termination --instance-id $id |
done |
# Attach unused EBS Volumes to an instance |
instance_id='i-abcd1234' |
letters=({a..j}) |
volumes=$(aws ec2 describe-volumes | jq -r '.Volumes[] | select(.State'available') | .VolumeId') |
lc=1 |
echo $volumes | while read id |
do |
echo 'Attaching volume on: $id' |
aws ec2 attach-volume --instance-id $instance_id --volume-id $id --device /dev/sd${letters[++lc]} |
done |
# Detach and delete secondary volumes on a machine |
aws ec2 describe-instances --instance-ids $instance_id | jq -r '.Reservations[0].Instances[0].BlockDeviceMappings | .[] | select(.DeviceName != '/dev/sda1') | .Ebs.VolumeId' | while read volume_id |
do |
aws ec2 detach-volume --volume-id $volume_id && |
aws ec2 wait volume-available --volume-ids $volume_id && |
aws ec2 delete-volume --volume-id $volume_id |
done |
# Copy everything from an account into an OSX clipboard |
aws ec2 describe-volumes | jq '[.Volumes[] | select(.State'available') | .VolumeId]' | pbcopy |
Aws Cli Commands Cheat Sheet
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment