AWS CLI (Amazon Web Service Command Line Interface) is an open-source command-line utility tool for managing Amazon web services. AWS CLI is a utility tool provided by AWS to manage resources. AWS API is directly accessible through AWS CLI. Using AWS CLI utility, you can create scripts for automating Amazon Web Services.
AWS CLI is available in version 1 and version 2. AWS recommends using AWS CLI version 2. If you already version 1, suggest to uninstall it or create symlink/alias with a different name.
In this tutorial, you will learn how to install AWS CLI on Ubuntu 20.04.
To install AWS CLI on Ubuntu you need to meet the following requirements:
- AWS Account
- Ubuntu 20.04 Server
- Sudo privileged user account
AWS CLI utility package is available in the default repository of Ubuntu 20.04. You can also use Python PIP or AWS installer to install the AWS CLI utility tool.
Method 1: Using AWS installer script
This is AWS recommended way of installation. This method work on Ubuntu and other Linux distributions such as CentOS, Fedora, Amazon Linux 1, and Amazon Linux 2.
For the latest version download the 64 bit version using curl command:
$ sudo curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
Note: For a specific version of the AWS CLI, append a hyphen and the version number to the filename.
Next step is to unzip the downloaded file, which will extract the file and create a directory named 'aws'. In unzip command not present, install unzip the package ($ sudo apt install unzip).
Run the following command to unzip the download the file:
$ sudo unzip awscliv2.zip
Now run the installer, using:
$ sudo ./aws/install
By default aws cli is installed in /usr/local/aws-cli, and a symbolic link is created in /usr/local/bin.
To verify the installation, type:
$ aws --version
aws-cli/2.1.33 Python/3.8.8 Linux/5.4.0-70-generic exe/x86_64.ubuntu.20 prompt/off
Method 2: Installing AWS CLI using APT
AWS CLI utility tool is available in the default repository of Ubuntu 20.04. To install the tool using APT, follow the following steps:
Update system packages:
Run the following command update system packages and repository index to latest.
$ sudo apt-get update
Once the system packages are updated, run the following command to install AWS CLI.
$ sudo apt-get install awscli -y
On completion the installation, run the following command to verify.
$ aws --version
You will get output similar as:
After installation, you can configure access to AWS account using AWS CLI. Before starting with aws configuration, you should have IAM user's Access key and Secret key provided with proper access.
Run the following command to configure access to aws account.
$ aws configure
Enter the following details accordingly:
- AWS Access Key ID [IAM user's Access key]
- AWS Secret Access Key [IAM user's secret key]
- Default region name [Aws region]
- Default output format [JSON format is fine]
You will have output similar as:
Uninstalling AWS CLI from ubuntu
To uninstall AWS CLI from ubuntu, you need to check AWS CLI installation path. Execute the following command to check installation directory of AWS CLI.
$ which aws
You will get output as:
Use the following command to check symlink and installation path.
$ ls -l /usr/local/bin/aws
You will get output as:
lrwxrwxrwx 1 root root 37 Mar 31 04:01 /usr/local/bin/aws -> /usr/local/aws-cli/v2/current/bin/aws
First remove the two symlinks, type:
$ sudo rm /usr/local/bin/aws $ sudo rm /usr/local/bin/aws_completer
Now delete the installation directory using the following command.
$ sudo rm -rf /usr/local/aws-cli
You have successfully removed AWS CLI from Ubuntu system.
Method 3: Installing AWS CLI using Python PIP
First, install python-pip on your system. Run the following command to install python-pip package.
$ sudo apt-get install python3-pip
Once the installation is completed, you need to upgrade PIP to latest version.
$ sudo pip3 install --upgrade pip
Now, Run the following command to install AWS CLI using PIP.
$ sudo pip3 install awscli
To verify the installation, run the following command.
$ python3 -m awscli --version
aws-cli/1.18.69 Python/3.8.5 Linux/5.8.0-45-generic botocore/1.16.19
The output shows that installed AWS CLI version is 1.18
Creating S3 Bucket using AWS CLI
Simple storage service, commonly know as s3 is a cloud storage service provided by Amazon web service to store and retrieve files. You might have an idea about google drive, dropbox for storing images, documents, and important files. AWS S3 is a similar kind of cloud service provided by AWS. You can create an S3 bucket using GUI as well as AWS CLI. You have configured AWS in the previous step, now let use AWS CLI commands to create an S3 bucket.
You can create as S3 bucket using s3api command followed by aws. Run the following command to find s3api commands.
$ aws s3api help
Now run the following command to create a simple bucket. In this example, I have selected the us-east-1 region and provided the bucket name 'example-bucket-12345' as my assumption. You can have chosen your preferable region and bucket name.
aws s3api create-bucket --bucket example-bucket-12345 --region us-east-1
You will get output as :
Use the following command to list created S3 bucket.
$ aws s3 list
Push Contents to S3 Bucket
Once an S3 bucket is created, you are now good to go for file storage. Run the following command to push your contents to an S3 bucket. In this example, I have sent a simple text file to the S3 bucket. You can push other files in similar ways.
$ aws s3 cp example.txt s3://example-bucket-12345
Where example.txt is the filename and example-bucket-12345 is the S3 bucket name. Once the upload is successful, you will get output similar as:
output: upload: ./example.txt to s3://example-bucket-12345/example.txt
You can list contents of the bucket using the following command.
$ aws s3 ls s3://example-bucket-12345
2021-03-28 23:31:47 0 example.txt
You can also use AWS CLI to delete the S3 bucket. Remember the point that, you may need to delete objects inside the S3 bucket before removing the bucket. Run the following command to delete objects from the S3 bucket. In this example, I Have removed the just pushed text file. You can select file names accordingly.
aws s3 rm s3://example-bucket-12345/example.txt
Once the bucket is empty, you can use following command to delete S3 bucket.
$ aws s3api delete-bucket --bucket example-bucket-12345 --region us-east-1
Where, example-bucket-12345 is my bucket name.
In this article, I have covered how to install AWS CLI on Ubuntu 20.04. You have learned how to verify the installation, configure the AWS, and uninstall AWS CLI from your device. Also, I have tried to show how to create an S3 bucket, push contents to the bucket, remove objects from the bucket, and delete the bucket. Any feedback and response are highly appreciated.