22 C
Jaipur
Monday, April 12, 2021

How to Install AWS CLI on Ubuntu 20.04

Must read

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.

In this tutorial, you will learn how to install AWS CLI on Ubuntu 20.04.

Prerequisites

To install AWS CLI on Ubuntu you need to meet the following requirements:

  • AWS Account
  • Ubuntu 20.04 Server
  • Sudo privileged user account

Installation

AWS CLI utility package is available in the default repository of Ubuntu 20.04. You can also use Python PIP to install the AWS CLI utility tool. In this tutorial, we will learn both methods.

Method 1: 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:

Checking AWS CLI version

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:

Configuring access to aws account

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:

$ /usr/bin/aws

Use the following command to check symlink and installation path.

$ ls -l /usr/bin/aws

You will get output as:

$ -rwxr-xr-x 1 root root 815 Jun 17  2020 /usr/bin/aws

Remove the installation directory using the following command.

$ sudo rm -rf /usr/bin/aws

You have successfully removed AWS CLI from your Ubuntu system.

Method 2: Installing AWS CLI using Python PIP

You can use Python PIP to install AWS CLI on your Ubuntu server. Python 2.x is not supported on Ubuntu 20.04 so you need to install Python 3.x.

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

Output:

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

Output:

Listing s3api features using aws cli

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 :

Creating S3 bucket using AWS CLI

Use the following command to list created S3 bucket.

$ aws s3 list

output:

Listing s3 bucket using AWS CLI

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

output:

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.

Conclusion

In this article, I have covered how to install AWS CLI on Ubuntu 20.04 using APT and PIP. 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.

Source link

- Advertisement -

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article