How Do We Use the AWS CLI?
Understand the various ways to run the AWS CLI, including Educative terminals, AWS CloudShell, and local terminals. Practice core commands and learn how to discover new ones using built-in help and official documentation.
Now that we know what the AWS CLI is, let’s go over how we can use it.
First, let’s take a look at the different environments we can run the AWS CLI in.
Environments for the AWS CLI
There are multiple equivalent ways to use the AWS CLI.
Use the Educative terminal from this course
This is obviously the easiest way to interact with the AWS CLI. Every time we’re required to use it, a terminal will be provided in this course.
Use the AWS CloudShell
This is a rather new and very handy feature of AWS. It’s not available in all regions yet, but if it is, we see a little icon in our AWS console resembling a prompt in the top bar next to the search bar.
We can see it in the screenshots above.
The AWS CloudShell is just like the built-in terminal on Educative or any other terminal. We can interact directly with the AWS CLI through it. It has one neat advantage—our AWS credentials are already preconfigured to be used with the AWS CLI. So, if we run any command here, it will be run as our AWS user.
Use a terminal on our computer or on a server
We can also install the AWS CLI on our computer or any server we operate. Because there are so many different operating systems and variants, this is out of scope for this course.
Interacting with the AWS CLI
Let’s put some of the theory we learned into practice and play around with the AWS CLI. We will also learn some tricks on how to work around the disadvantages of learning a new CLI and speed up the process.
A quick recap of the commands we have already used:
aws configure listaws ec2 describe-instances
Let’s try them out again in the terminal below:
Type the first one and press “Enter.” We should see the following output:
Why did this work? Why didn’t we need to enter the access key ID and secret access key again?
The Educative terminal remembers the environment variables if we have configured them once through the Educative interface. We can see these in the terminal above. The terminal will reuse them here.
Now, let’s run aws ec2 describe-instances again. The output should look like the following widget if we started with a new account. Otherwise, it may show existing instances.
Again, this command uses the environment variables that are already configured. Because we gave our IAM user the permissions to interact with EC2, we can run this command in any terminal that uses our AWS credentials.
How to learn new commands
But how would we know about any other commands we can use with the AWS CLI?
The most obvious way is to consult the AWS CLI Documentation or the AWS CLI Command Reference. The AWS CLI Reference has chapters for each subcommand of the AWS CLI. It can be a rather dry read at times but is the most complete resource on the AWS CLI.
There is also a very handy command built into the AWS CLI itself. We can attach help behind every command and subcommand we want to use:
Try it out in the terminal below:
We can use the “PgUp” and “PgDn” (or “Fn+Arrow Up” and “Fn+Arrow Down” on a Mac) or the arrow keys to navigate the help document. If we want to exit it, just enter q.
That’s it for now! In the next lesson, we’ll see how we can run an EC2 instance through the CLI!