The AWS Command Line Interface (CLI) has become an invaluable tool for developers, DevOps engineers, and cloud architects to efficiently manage their AWS environments. With its simple yet powerful commands, the AWS CLI allows automation of repetitive tasks, infrastructure as code, and direct control of AWS services from the comfort of your terminal.
In this comprehensive guide, we‘ll cover what exactly is the AWS CLI, its key capabilities, benefits, and then provide detailed instructions to get it installed and configured across major platforms like Windows, macOS, Linux distributions, and Docker.
What is AWS CLI?
The AWS CLI is an open-source tool developed and maintained by Amazon Web Services (AWS). It allows you to control multiple AWS services directly from the command line within your terminal or shell.
Some key highlights:
-
Provides direct access to public APIs of AWS services like EC2, S3, IAM, CloudFormation etc.
-
Enables automation of tasks which otherwise require manual work through the AWS console
-
Supports DevOps practices like Infrastructure as Code (IaC)
-
Available on Windows, macOS, Linux and Docker
-
Open source tool maintained by AWS but can be used with other cloud providers
The AWS CLI was first launched in 2012 as a Python toolkit to manage AWS services. Over the years, it has evolved to include two major versions:
-
Version 1.x – Available for backward compatibility with old scripts written for AWS CLI v1.
-
Version 2.x – The latest major release with support for new features. Recommended for general usage.
In this guide, we will focus on installing version 2.x which is the current production-ready version.
Why is the AWS CLI Useful?
Here are some of the main benefits and use cases of the AWS CLI:
-
Infrastructure as Code – Manage infrastructure through code for reproducibility and standardized deployments.
-
Faster scaling – Provision resources faster through CLI compared to console.
-
Automation – Automate repetitive tasks like starting and stopping instances.
-
Direct access – Control services like EC2, S3, CloudFormation directly from terminal.
-
Flexibility – Switch between AWS accounts, regions, output formats easily.
-
Monitoring – Check billing, resource usage, service limits with CLI.
-
Scripting and control – Orchestrate tools, write scripts for complex workflows.
According to the 2021 State of DevOps report by Puppet, 74% of high-performing engineering teams use infrastructure as code for provisioning. The AWS CLI makes IaC with AWS easier through its simple but powerful commands. Teams can codify and automate their infrastructure builds reliably and repeatedly.
The CLI also enables engineers to quickly build tools and scripts tailored to their specific needs. Rather than manually logging into the AWS console to launch instances or configure networks, they can automate these tasks programmatically with the CLI.
How to Install AWS CLI on Different Platforms
The AWS CLI is available on all major platforms like Linux, Windows, macOS and Docker.
Let‘s go through how to install the latest version of AWS CLI 2.x on each system:
Linux
On Linux x86 (64-bit), the official method is using a bundled Zip archive containing the executable:
$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
The above requires a minimal 64-bit Linux environment with unzip, glibc, groff and less packages. It has been tested on Ubuntu, Debian, CentOS, Fedora, Amazon Linux etc.
To verify, run:
$ aws --version
aws-cli/2.2.5 Python/3.8.8 Linux/4.14.133-113.105.amzn2.x86_64 botocore/2.0.0
macOS
On macOS, AWS CLI can be installed via a graphical installer (.pkg file) or from the terminal using CLI commands.
For the GUI method, download the PKG installer from https://awscli.amazonaws.com/AWSCLIV2.pkg and double click to launch the installer wizard. Accept the terms and keep default options for a normal install.
To install from terminal, first download the PKG:
$ curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
For a system-wide install use:
$ sudo installer -pkg AWSCLIV2.pkg -target /
For current user install without admin rights:
-
Create
choices.xmlfile with install path like/Users/username -
Run installer using XML file:
$ installer -pkg AWSCLIV2.pkg -target CurrentUserHomeDirectory -applyChoiceChangesXML choices.xml
- Create symlinks for
awsandaws_completer:
$ sudo ln -s /folder/installed/aws-cli/aws /usr/local/bin/aws
$ sudo ln -s /folder/installed/aws-cli/aws_completer /usr/local/bin/aws_completer
Confirm the CLI version:
$ aws --version
aws-cli/2.1.29 Python/3.7.4 Darwin/18.7.0 botocore/2.0.0
Windows
On Windows 64-bit, download the MSI installer from https://awscli.amazonaws.com/AWSCLIV2.msi.
To install from PowerShell as admin, run:
msiexec.exe /i https://awscli.amazonaws.com/AWSCLIV2.msi
Alternatively, double click the MSI file and follow prompts.
Verify in Command Prompt:
C:\> aws --version
aws-cli/2.2.7 Python/3.8.8 Windows/10 exe/AMD64 prompt/off
Docker
For Docker usage, an official amazon/aws-cli Docker image is available.
Pull the latest image:
$ docker pull amazon/aws-cli
Now directly run AWS CLI commands:
$ docker run --rm -it amazon/aws-cli aws s3 ls
# Lists S3 buckets
The --rm flag automatically removes the container after command exit.
You can also create an alias for convenience:
$ alias aws=‘docker run --rm -it amazon/aws-cli‘
$ aws ec2 describe-instances
# Describes EC2 instances
Configuring the AWS CLI
Once installed, the next step is to configure the AWS CLI with your account credentials and settings.
The aws configure command will walk you through these initial settings:
$ aws configure
AWS Access Key ID: <your_access_key>
AWS Secret Access Key: <your_secret_key>
Default region name [us-east-1]: <your_default_region>
Default output format [json]: json
This stores the config and credentials in a file under ~/.aws/ folder. For advanced configuration, you can directly modify config and credentials files here.
Some common config settings:
- Named profiles for different accounts/roles
- Environment variables for credentials
- Configuring proxy, TLS certificates
- CLI output formatting
- Custom AWS endpoints
Refer to AWS CLI configuration docs for more details.
Summary
The AWS Command Line Interface (CLI) provides developers and system administrators a powerful way to manage AWS services directly from their terminal. It is a must-have tool to automate infrastructure management and deployments.
We covered a brief overview of AWS CLI, its benefits, and then how to install the latest version 2 on Windows, macOS, popular Linux distros, and Docker. You also learned how to do initial configuration using aws configure to integrate with your AWS account.
From here, you can start using the wide range of aws commands to launch EC2 instances, copy S3 objects, deploy CloudFormation stacks and more. The AWS CLI enables you to easily script and automate your infrastructure builds consistently and repeatedly.