Saturday, December 17, 2016

HowTo: Install AWS CLI on Both Windows and Linux

Several years ago before the unified AWS CLI was released I wrote about installing the EC2 command line tools. Now it's time to update that.

It goes without saying that over the decade Amazon has been providing cloud services their interfaces and tools have matured greatly (along with their overall offerings). Early on Amazon didn't even have web console and we had to rely on a disparate offering of command line tools for managing S3, EC2, ELB, etc. Finally, in the fall of 2013 Amazon released the AWS CLI, which is a unified set of command line tools that works similarly across platforms (Windows, Linux, Mac) and across AWS services. It's definitely nice to use the same (or nearly the same) syntax on both Windows and Linux machines to perform various functions.

Installing AWS CLI on Linux (Ubuntu)
The easiest way I've found to install and update the AWS CLI on Ubuntu (and Debian-based linux distros) is using apt, with this simple one-liner:

sudo apt install awscli -y

Once installed or updated check the version with:

aws --version

Installing AWS CLI on Windows
Assuming you are installing on Windows 2008 R2 or later, we'll leverage the native capability of PowerShell to use Invoke-WebRequest (AKA wget) to retrieve the latest installer. I'm also assuming you have a directory c:\temp. If not, create it or use a directory of your choosing. Note: these steps can be used to update the AWS CLI to the latest version as well. If you aren't running at least PS v3 you can update PowerShell to get this functionality. And, you'll have to restart PowerShell if you are doing a new install of the AWS CLI to access them.

To download the latest version of the installer in PowerShell run:

wget -uri https://s3.amazonaws.com/aws-cli/AWSCLI64.msi -OutFile c:\temp\AWSCLI64.msi

Launch the installer (I'm using the /passive switch to accept defaults and not have to answer any questions):

c:\temp\AWSCLI64.msi /passive

In under a minute I am able to download and execute the installer, which works both for first time installs and updating to the latest version. Just like on Linux the version can be checked with (make sure the installer completed before running):

aws --version

Whether you are using the AWS CLI on Windows or Linux you can run the aws configure command to enter the default values; AWS Access Key, Secret, default region and default output type. Then you can run AWS commands to your heart's content.

Once the CLI is installed and configured you can run various commands to test connectivity to AWS services.

aws s3 ls s3:// (list all S3 buckets)

aws ec2 describe-instances

No comments:

Post a Comment