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 have version 1, suggest uninstalling it or create symlink/alias with a different name.
In this guide, 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 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:
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.
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 update
Once the system packages are updated, run the following command to install AWS CLI.
sudo apt 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:
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 the installation directory of AWS CLI.
which aws
You will get the output as:
/usr/local/bin/aws
Use the following command to check symlink and installation path.
The output shows that the 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
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.
Use the following command to list created S3 bucket.
aws s3 list
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.
In this guide, we 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, we 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.
If this resource helped you, let us know your care by a Thanks Tweet.
Did you find this article helpful?
We are glad you liked the article. Share with your friends.
Comments