Cloud computing is one of the higly adopted technologies today. This model involves delivering computing resources over the internet, such as servers, storage, databases, applications, and other IT services. Rather than owning and maintaining physical servers and infrastructure, cloud computing allows users to access these resources on-demand, using a pay-per-use model, through a network of remote servers hosted on the internet. There are several features and benefits associated with cloud computing. The notable ones are cost savings, reliability, availability, global accessibility, scalability and flexibility.
There are several cloud providers, they include Amazon Web Services (AWS), Microsoft Azure, Google Cloud Platform (GCP), IBM Cloud, Oracle Cloud, Alibaba Cloud etc. As a system administrator/cloud engineer, you are tasked to provision and maintain the cloud resources. Most of these cloud providers allow their users to manage the resources from their web portals. However, most users prefer managing the resources from the command line. This gives them the freedom to automate tasks via the command line.
The AWS Command Line Interface (CLI) is a unified tool that allows users to manage AWS services and resources from the command line. It provides a command-line interface from which users can interact with various AWS services, such as EC2 instances, RDS databases, S3 buckets, and many others, using a set of commands. It is built on top of the AWS SDKs (Software Development Kits), which are available in various programming languages. It provides a simple, yet powerful way to interact with AWS services without the need for a graphical user interface (GUI).
It offers several features and benefits to AWS users, among them are:
- Automation: users can automate and script various tasks, such as deploying applications, creating and managing AWS resources, and configuring security settings. You can use scripts to automate these tasks, which can save time and reduce the risk of errors.
- Cross-platform: It supports a wide range of operating systems, including Windows, macOS, and Linux, and can be easily installed and configured on any machine.
- Security: The AWS CLI provides secure access to AWS resources. You can use AWS Identity and Access Management (IAM) to control access to resources, and you can encrypt data in transit and at rest.
- Speed and efficiency: With the AWS CLI, you can perform tasks quickly and efficiently. You can use simple commands to perform complex tasks, and you can easily script repetitive tasks to save time.
- Flexibility: The AWS CLI is available on multiple platforms, including Windows, Linux, and macOS. You can use it with a variety of programming languages, including Python, Ruby, and Node.js.
- Integration with other tools: The AWS CLI integrates with many other tools, including AWS CloudFormation, AWS CodeDeploy, and AWS CodePipeline. You can use it to automate your DevOps workflows and integrate with your existing tools and processes.
Today we will walk through how to install and use AWS CLI on Linux | macOS.
Getting Started
The AWS CLI works with the below Python versions:
- 3.7.x and greater
- 3.8.x and greater
- 3.9.x and greater
- 3.10.x and greater
- 3.11.x and greater
After the deprecation for Python 2.7 on 2021-01-15 support for this version was dropped and users were advised to upgrade their version of Python or pin the version of the AWS CLI. Also on 2022-05-30, support for Python 3.6 was ended after the Python Software Foundation announced the end of support for the runtime on 2021-12-23.
1. Install AWS CLI on Linux | macOS
There are several methods to install the AWS CLI on Linux | macOS. In this guide, we will cover the below methods.
Method 1 – Install AWS CLI on Linux | macOS Using PIP
This is the most common and easiest method to install AWS CLI on Linux | macOS. For this method, it is recommended to have the following:
pip
: 9.0.2 or greatersetuptools
: 36.2.0 or greater
Once the requirements have been met, you can install the AWS CLI in a virtualenv
with the command:
python3 -m pip install awscli
##OR
python -m pip install awscli
If you are not using the virtualenv
, then you can do a global installation with the command:
sudo python3 -m pip install awscli
##OR
sudo python -m pip install awscli
Sample execution output:

You can also install the CLI for a specific user:
python3 -m pip install --user awscli
##OR
python -m pip install --user awscli
You can also upgrade to the latest available version:
python3 -m pip install --upgrade awscli
##OR
python -m pip install --upgrade awscli
During the installation on macOS, you can encounter an error regarding the version of six
that came with distutils
in El Capitan. To resolve this, use the --ignore-installed
option as shown:
sudo python -m pip install awscli --ignore-installed six
Method 2 – Install the AWS CLI using the bundled installer
You can use the bundled installer to install the AWS CLI version 1 from the command line on Linux | macOS. You need to have Python and python-venv packages installed. Then, obtain the latest version of the AWS CLI with the command:
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
sudo ./aws/install
Extract the file:
unzip awscliv2.zip
Now run the bundled installer:
sudo ./aws/install
The installer will install the AWS CLI at /usr/local/aws and creates the symlink aws at the /usr/local/bin directory. The -b option is used to create a symbolic link to allow the user to run the AWS CLI by entering aws
from any directory.
This installation will use the default Python version to run. If you have another Python installation for example Python3, you can specify it during the installation with the command:
sudo /usr/bin/python3 awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
Use the command below to identify the Python location:
which python3
##OR
which python
Sample execution output:

2. Configure the AWS CLI on Linux | macOS
Once the installation is complete, verify the installed version with the command:
$ aws --version
aws-cli/2.15.19 Python/3.11.6 Linux/5.10.205-195.807.amzn2.x86_64 botocore/2.4.5
Before we use the AWS CLI, we are required to configure the AWS credentials. This can be achieved using a number of ways:
- Configuration command
- Environment variables
- Shared credentials file
- Config file
- IAM Role
a. Using the Configuration command
The easiest method of them all is by running the command:
$ aws configure
AWS Access Key ID: MY_ACCESS_KEY
AWS Secret Access Key: MY_SECRET_KEY
Default region name [us-west-2]: eu-west-1
Default output format [None]: json
b. Using Environment variables
You can also configure the creds using environment variables as shown:
export AWS_ACCESS_KEY_ID=<access_key>
export AWS_SECRET_ACCESS_KEY=<secret_key>
c. Using shared credentials file
This method involves creating an INI formatted file like this.
mkdir ~/.aws
Create the file:
$ vim ~/.aws/credentials
[default]
aws_access_key_id=MYACCESSKEY
aws_secret_access_key=MYSECRETKEY
[testing]
aws_access_key_id=MYACCESKEY
aws_secret_access_key=MYSECRETKEY
Replace all the variables appropriately. You can also place the shared credentials file in a different location than the one specified above and export the path with the command:
export AWS_SHARED_CREDENTIALS_FILE=/path/to/shared_credentials_file
d. Using a Config File
This method almost resembles the shared credentials one.
mkdir ~/.aws
Create an INI formatted file:
$ vim ~/.aws/config
[default]
aws_access_key_id=<default access key>
aws_secret_access_key=<default secret key>
# Optional, to define default region for this profile.
region=us-west-1
[profile testing]
aws_access_key_id=<testing access key>
aws_secret_access_key=<testing secret key>
region=us-west-2
If you used a different path for the file, export it:
export AWS_CONFIG_FILE=/path/to/config_file
For both the shared credentials file and the configuration file we have multiple profiles specified. You can then specify the preferred profile for use with the --profile
option. If not specified, then the default
profile will be used.
e. Using IAM Roles
This is the highly recommended method if you are using the AWS CLI on an EC2 instance. The IAM Roles are a great way to get the credentials automatically installed on your instance.
If you are using IAM Roles, the AWS CLI will find and use them automatically. Moreso, a number of other variables can be configured either with environment variables, configuration file entries, or both. For more, refer to the AWS Tools and SDKs Shared Configuration and Credentials Reference Guide.
3. How to Use the AWS CLI on Linux | macOS
Now once the configurations have been made, you are set to use the AWS CLI on Linux | macOS to interact with the AWS resources. The AWS CLI command has the following syntax:
aws <command> <subcommand> [options and parameters]
For example, to manage EC2 instances, use the commands:
To list the instances
aws ec2 describe-instances
Sample Output:

To avoid a long output, you can filter to obtain the instance ID.
$ aws ec2 describe-instances --filters "Name=instance-type,Values=t2.micro" --query "Reservations[].Instances[].InstanceId"
[
"i-069533e79cd6fcfbb"
]
You can then terminate/deletes the desired instance
aws ec2 terminate-instances --instance-ids i-069533e79cd6fcfbb
Sample Output:

To stop/start the instance, use:
##START
aws ec2 start-instances --instance-ids i-069533e79cd6fcfbb
##STOP
aws ec2 stop-instances --instance-ids i-069533e79cd6fcfbb
Listing the S3 buckets, the command will be:
aws s3 ls
You can also view the files in an S3 bucket. For example:
$ aws s3 ls s3://mybucket
LastWriteTime Length Name
------------ ------ ----
PRE myfolder/
2013-09-03 10:00:00 1234 myfile.txt
You can perform recursive uploads and downloads in a single folder-level command. For example:
$ aws s3 cp myfolder s3://mybucket/myfolder --recursive
upload: myfolder/file1.txt to s3://mybucket/myfolder/file1.txt
upload: myfolder/subfolder/file1.txt to s3://mybucket/myfolder/subfolder/file1.txt
You can also sync files between the local folder and the S3 bucket. For example:
$ aws s3 sync myfolder s3://mybucket/myfolder --exclude *.tmp
upload: myfolder/newfile.txt to s3://mybucket/myfolder/newfile.txt
Verdict
We have come to the end of this guide on how to install and use AWS CLI on Linux | macOS. You have the power to automate deployments on the AWS platform using the CLI tool. I hope this was significant to you.
See more:
- How To Deploy EKS Cluster on AWS using Terraform
- How To Mount AWS EFS File System on EC2 Instance
- AWS ECS: Automatically Update ECS Services using CodePipeline