Join Sharif Nijim for an in-depth discussion in this video The AWS Command Line Interface (CLI), part of Amazon Web Services: High Availability.
- [Narrator] Over the years, AWS has done a phenomenal job evolving the web console into a remarkably approachable powerful tool for managing infrastructure. Throughout this course, I'll primarily be using the web console, however, only through automation is the management of your AWS infrastructure scalable. One of the many available automation tools is the AWS command line interface, or CLI. I'll be using it at times throughout this course, so let's take a moment to see how to install and configure it.
Here I've opened a web browser on the left and a terminal window on the right. With this setup I can read instructions in the browser. I can also copy commands from the web browser into my terminal. Let's go ahead and do a Google search for how to download the AWS CLI. The very first link will take you to the comprehensive AWS documentation, where you can download and install the CLI. Scrolling down on this page, I see that the CLI is available for Windows, as well as Linux, OS X or Unix.
I happen to be on a Mac, so I'm going to use the bundled installer for OS X. As you can see the prerequisites, we obviously need the operating system, as well as Python. I'm going to run the Python version command to make sure I have a version that's compatible. Great, I have Python 2.7.10 installed, which meets the minimum requirement. Scrolling down a little bit more, I can see that AWS provides the three commands I need to download and install the CLI. I can simply highlight them, copy them and paste them into my terminal.
The first command downloads the CLI bundle to my local machine. The second command simply unpacks the local CLI bundle. This third command is what does the actual install. The password it's asking me for is my local password on my Mac. Okay, looks like that finished successfully. You can see in the output, it says I can now run usr/local/bin/aws -version to make sure that it actually works. So I'm just going to copy that, paste it in and run it.
Great, it looks like I'm running version 1.10.53 of the AWS CLI. Let's also just confirm that usr/local/bin is in my path, by typing which aws. Wonderful, that means I can type aws on the command line instead of fully qualifying it. On Windows, you can use the MSI installer to make the AWS CLI available from the Windows command prompt. However, if you have Windows 10, I highly recommend installing the Windows subsystem for Linux.
This gives you a bash environment. Detailed instructions on how to install the Windows subsystem for Linux can be found on Microsoft's website. I will be using bash throughout this course, so it will be much easier to follow along on Windows if you use the Windows subsystem for Linux. I can start the bash environment by opening the Windows menu and typing bash. Bash on Ubuntu on Windows is what I'm looking for, so I can make sure it's selected and hit the enter key. Great, that pops me up a bash environment.
As of this recording, the bash environment is still in beta. As such, there are a variety of utilities which are not installed by default. One of those utilities is the Python package manager, Pip. Let's go ahead and install Pip using the instructions on the AWS Install CLI page. Unintuitively for Windows users, we have to use the instructions for Linux. First I need to download the installation script. I can simply copy the command and paste it into my bash environment. The next thing I need to do is run the script with Python.
Wonderful, if you remember from the bundled install instructions, it uses the unzip utility. This is something that is not installed by default in this environment. Let's go ahead and install the unzip utility using apt-get, a common way of managing packages on Linux. Wonderful, that installed successfully. At this point we can either use the bundled installer commands to install the CLI, or we can simply use Pip. Since we just installed Pip, let's use it to install the CLI.
Once again, we need to use the Linux command. I simply copy it in and paste it into my bash shell. We can confirm that the CLI was installed correctly by typing which aws. One thing to note about CLI configuration. It stores configuration information in a .aws directory under your local users home directory. One feature the CLI supports is the concept of named profiles.
That is, you can specify a named profile as a parameter to any CLI command. When you do that, it will reference the configuration options for that named profile. This is very useful when you need to access multiple AWS environments using different credentials. When I initially configure the CLI, I like to specify junk values in order to force me to use the named profiles I so strongly prefer. Let's see what those values are by running the AWS configure command. The first thing it asks for is my AWS access key ID.
This is a unique ID for a specific credential. I'm going to specify a junk value, none. The second thing it looks for is the AWS secret access key, which is the password that accompanies the key ID. Again, I'm going to specify a junk value. The third thing it looks for is the default region name. The region name, when passed into the CLI, tells the CLI what region to run the command in. Finally, it asks for a default output format.
Let's take a look at the credentials file. We see that in the credentials file, the access key ID and secret access key, also contain the junk default values that I put in. In this course, I'll be using two separate AWS accounts. I've already created credentials for those accounts. Now let's set up the CLI, so that I have named profiles, so I can reference the accounts by profile name. The first thing we'll do is copy in the config information. I'm going to use the VI editor to make my changes.
The first thing I'm going to open is the config file for the CLI, and the second file I'm going to open is my configuration file. In the config file that the CLI references, the only profile we see is the default one, with the junk values for output and region. Opening up my local configuration information, I see that I have two profiles set up. The first one is my snijim.dev.admin profile and the second one is my snijim.research.admin profile.
Those happened to reference two separate accounts. I'm going to copy that profile information and go back into the config file that the CLI references. I've simply appended the named profiles to the CLI config file. I see that for my dev account, the default region is eu-west-1, and for my research account, the default region is us-west-2. Let's do the same thing for the credentials file. Again, the credentials file simply contains a default profile with junk values.
Meanwhile my local credentials file actually has valid credentials. I'm going to do the same thing and copy those credentials, go back to my CLI credentials file and paste them in. Now, for my dev profile and my research profile I see that I actually have valid credentials. Now that that bit of tedious configuration is done, I'm ready to use the CLI.
This course is also part of a series designed to help you prepare for the AWS Certified SysOps Administrator – Associate certification exam.
- What is high availability?
- Designing for failure
- Exploring Route 53
- Working with machine images
- Setting up load balancing
- Creating groups
- Working with auto scaling
- Improving relational database availability
- Setting up an elastic file system