Join Sharif Nijim for an in-depth discussion in this video Installing the AWS CLI, part of Amazon Web Services: Monitoring and Metrics.
- [Instructor] 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, OSX or Unix.
I happen to be on a Mac, so I'm going to use the bundled installer for OSX. 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 user local bin AWS dash 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 user 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 dot AWS directory, under your local user's 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 name 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.
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 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 happen 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 One, and for my research account, the default region is US West Two. 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.
This course includes trademarks owned by Amazon Web Services. This course has not been prepared, approved, or endorsed by Amazon Web Services.
- Exploring monitoring tools
- Understanding CloudWatch
- Using CloudWatch alarms
- Monitoring EC2 memory
- Using AWS Config
- Understanding AWS logging and ElasticSearch
- Combining CloudWatch and Lambda