Situatie
The AWS CLI is an essential tool for developers and sysadmin to automate and interact with AWS cloud services. It is an open-source tool built on the AWS SDL for Python. As a result, you no longer need to use AWS Management Console. Instead, you can use Linux terminal and commands for managing AWS resources.
Installing AWS cli on Linux
- Open the terminal application.
- Then type command as per your Linux distro to install aws cli kit:
- Debian/Ubuntu Linux user, type:
$ sudo apt install awscli
- Fedora Linux user, type:
$ sudo dnf install awscli
- RHEL/CentOS/Rokcy/Alma Linux user, type (first, turn on ELEP repo and then):
$ sudo dnf install awscli
- Alpine Linux user, type:
# apk add aws-cli
- Arch Linux user, type:
$ sudo pacman -S aws-cli
- OpenSUSE/SUSE Linux user, type:
$ sudo zypper in aws-cli
- Install AWS CLI version 1.x using PIP generic method:
$ python3 -m pip install awscli
Do you want AWS cli version 2? Try:$ python3 -m pip install awscliv2
Make sure you include ~/.local/bin/ in your $PATH. For example, here is how to set up PATH on your Linux:
$ ~/.local/bin/awscliv2 --install# Step #1. Set PATH variable #
$ echo 'export PATH=$PATH:~/.local/bin' >>~/.bashrc
# Step #2. Set bash alias too #
$ echo 'alias aws="awsv2"' >>~/.bashrc
# Step #3. Use the source command to load changes #
$ source ~/.bashrc
- Debian/Ubuntu Linux user, type:
- Once installed, find out AWS CLI version, run:
$ aws --version
Depending upon your package manager and Linux distro, you may get the latest or older version. For instance, here is the output from my Ubuntu 20.04 LTS developer workstation:aws-cli/1.18.69 Python/3.8.10 Linux/5.13.0-35-generic botocore/1.16.19
Here is outputs from v2:
2.1.1 AWS CLI v2 command: /home/ubuntu/.awscliv2/binaries/aws aws-cli/2.4.28 Python/3.8.8 Linux/5.13.0-37-generic exe/x86_64.ubuntu.22 prompt/off
- Next, you need to configure AWS cli with API keys. Log in to the AWS management console and grab API access keys if you don’t have any. Then configure it as follows:
$ aws configure
- So far, you have installed AWS cli. Then configured access, and now it is time to test it. First, I will run the ‘aws s3 ls’ command to list your aws s3 resources:
$ aws s3 ls
Here is what I see when everything is configured correctly:2016-07-25 16:11:06 xyz-project-freenas 2020-07-03 13:55:47 xyz-project-forum .... ..
A note about credentials file
Your aws CLI credentials are stored in plain text inside ~/.aws/ directory. Therefore, do not share ~/.aws/ directory and files. You can view it using the cat command:
$ cat ~/.aws/credentials
It is possible to store credentials in an encrypted format. The other option is to use and enable AWS Multi-Factor Authentication (MFA). It is a best practice that adds an extra layer of protection for your credentials.
Leave A Comment?