Aws clI: 10 useful commands you may not know
Hii folk
🚀 Excited to share day 11 of comprehensive 30 days of AWSlearning path 🎮🎉👇
Welcome to Day 11 of our comprehensive 30-day aws learning path! In today’s session, we’ll be delving into the fascinating world of cloud AWS CLI commands . By the end of this lesson, we’ll have a solid understanding of cloud how it’s functions
Our goal is to focus on fundamentals then identify and learn the most commonly used services first and learn specialized services on a need to know basis.
The AWS console is certainly very well laid out and, with time, becomes very easy to use. However, if you are not using the AWS CLI (Command Line Interface) from your local terminal, you may be missing out on a whole lot of great functionality and speed. If you are not yet comfortable with the AWS Command Line Interface,
Here are some unknown and Commonly Used Commands in AWS CLI
1.Creating EC2 instances
Amazon Elastic Compute Cloud or EC2 is an Amazon web service that delivers simple web-scale cloud computing for developers. The example below shows how the command line tool makes it easy to start multiple EC2 instances.
$ aws ec2 start-instances — instance-ids i-4j3423ie i-32u89uf2
2.List all paused EC2 instances and showed why each one stopped
When you’re managing multiple EC2 instances, listing the paused instances and showing the reason for each can be a minor issue with the standard GUI. The example below shows how to use the AWS CLI (and jq) to do this easily:
aws ec2 description-instance — filter name=instance-state-name, value=stopped — region eu-west-1 — output json | jq -r .Reservations[].Instances[] .StateReason.Message
3. Delete an S3 bucket and all its contents with just one command
Sometimes you may end up with a bucket full of hundreds or thousands of files that you no longer need. If you have ever had to delete a substantial number of items in S3, you know that this can be a little time-consuming. The following command will delete a bucket and all of its content including directories:
aws s3 rb s3://bucket-name –force
4. Recursively copy a directory and its subfolders from your PC to Amazon S3
If you have used the S3 Console, at some stage, you’ve probably found yourself having to copy a ton of files to a bucket from your PC. It can be a little clunky at times, especially if you have multiple directory levels that need to be copied. The following AWS CLI command will make the process a little easier, as it will copy a directory and all of its subfolders from your PC to Amazon S3 to a specified region.
aws s3 cp MyFolder s3://bucket-name — recursive [–region us-west-2]
5. Display subsets of all available ec2 images
The following will display all available ec2 images, filtered to include only those built on Ubuntu (assuming, of course, that you’re working from a terminal on a Linux or Mac machine).
aws ec2 describe-images | grep ubuntu
Warning: this may take a few minutes.
6. List users in a different format
Sometimes, depending on the output format you chose as default when you invoke long lists — like a large set of users — the display format can be a little hard to read. Including the –output parameter with, say, the table argument, will display a nice, easy-to-read table this one time without having to change your default.
aws iam list-users –output table
7. List the sizes of an S3 bucket and its contents
The following command uses JSON output to list the size of a bucket and the items stored within. This might come in handy when auditing what is taking up all your S3 storage.
aws s3api list-objects — bucket BUCKETNAME — output json — query “[sum(Contents[].Size), length(Contents[])]”
8. Move the S3 bucket to a different location
If you need to quickly move an S3 bucket to a different location, then this command just might save you a ton of time.
aws s3 sync s3://oldbucket s3://newbucket — source-region us-west-1 — region us-west-2
8. List users by ARN
“jq” is like sed
for JSON data – you can use it to slice, filter, map, and transform s1tructured data with the same ease that sed
, awk
, grep
and friends let you play with non-JSON text.
Armed with that knowledge, we can now nicely list all our users, but only show their ARNs.
aws iam list-users –output json | jq -r .Users[].Arn
Note: jq, might not be installed on your system by default. On Debian-based systems (including Ubuntu), use Sudo apt-get install jq
10. List all of your instances that are currently stopped and the reason for the stop
Here’s another use of the JSON output parameter. This one will list all of your stopped instances and, best of all, show the reason that they were stopped:
aws ec2 describe-instances — filters Name=instance-state-name,Values=stopped — region eu-west-1 — output json | jq -r .Reservations[].Instances[].StateReason.Message
Thanks for reading
I hope found this useful?
✅Reshare this with others so that it helps more people
✅Tag your colleagues and friends who you think will need this