AlmaLinuxRHEL Based

How To Install AWS CLI on AlmaLinux 9

Install AWS CLI on AlmaLinux 9

The Amazon Web Services Command Line Interface (AWS CLI) is an essential tool for managing AWS services efficiently. It provides a unified interface to interact with various AWS services through command-line instructions, enabling automation and streamlining of AWS management tasks. This comprehensive guide will walk you through the process of installing AWS CLI on AlmaLinux 9, a robust and enterprise-ready Linux distribution.

Whether you’re a system administrator, developer, or DevOps engineer, mastering the AWS CLI installation on AlmaLinux 9 will empower you to manage your AWS resources more effectively. This article covers multiple installation methods, configuration steps, and best practices to ensure you have a smooth experience with AWS CLI on your AlmaLinux 9 system.

Prerequisites

Before we dive into the installation process, ensure that you have the following prerequisites in place:

  • An AlmaLinux 9 system with at least 1GB of RAM and 10GB of disk space
  • A user account with sudo privileges for performing administrative tasks
  • A stable internet connection for downloading necessary packages and the AWS CLI installer
  • Basic familiarity with the Linux command line interface

Understanding AWS CLI

The AWS Command Line Interface (CLI) is a unified tool provided by Amazon Web Services to manage various AWS services directly from the command line. It offers several advantages over the AWS Management Console:

  • Automation: AWS CLI allows you to script and automate AWS management tasks, saving time and reducing human error.
  • Consistency: It provides a consistent interface across different AWS services, making it easier to learn and use.
  • Speed: For many operations, using the CLI can be faster than navigating through the web-based console.
  • Integration: AWS CLI can be easily integrated with other command-line tools and scripts, enhancing your workflow.

While the AWS Management Console offers a user-friendly graphical interface, the AWS CLI excels in scenarios requiring automation, repetitive tasks, or integration with other tools. Many DevOps professionals prefer the CLI for its flexibility and power in managing AWS resources efficiently.

Installation Methods

There are two primary methods to install AWS CLI on AlmaLinux 9:

  1. Using pip (Python package manager)
  2. Using the bundled installer provided by AWS

Both methods have their advantages, and the choice depends on your specific requirements and system configuration. We’ll cover both approaches in detail to help you choose the most suitable option for your needs.

Method 1: Installing AWS CLI using pip

Installing AWS CLI using pip is straightforward and allows for easy updates. Follow these steps to install AWS CLI using pip:

Step 1: Installing Python and pip

AlmaLinux 9 comes with Python 3 pre-installed. However, we need to ensure we have pip installed. Run the following command to install pip:

sudo dnf install python3-pip

Step 2: Upgrading pip

It’s a good practice to upgrade pip to the latest version:

pip3 install --upgrade pip

Step 3: Installing AWS CLI

Now, we can install AWS CLI using pip:

pip3 install awscli --upgrade --user

The --user flag installs AWS CLI for the current user, avoiding potential permission issues.

Step 4: Verifying the installation

To verify that AWS CLI has been installed correctly, run:

aws --version

This should display the version of AWS CLI installed on your system.

Method 2: Installing AWS CLI using the bundled installer

The bundled installer is an alternative method provided by AWS. It includes all dependencies and can be useful in environments where pip is not available or allowed. Follow these steps to install AWS CLI using the bundled installer:

Step 1: Downloading the installer

First, download the AWS CLI installer:

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"

Step 2: Unzipping the installer

Unzip the downloaded file:

unzip awscliv2.zip

Step 3: Running the installer

Run the install script:

sudo ./aws/install

Step 4: Verifying the installation

Verify the installation by checking the AWS CLI version:

aws --version

Configuring AWS CLI

After installing AWS CLI, you need to configure it with your AWS credentials. Follow these steps:

Step 1: Creating an IAM user in AWS Console

  1. Log in to the AWS Management Console
  2. Navigate to the IAM (Identity and Access Management) service
  3. Create a new IAM user with programmatic access
  4. Assign appropriate permissions to the user

Step 2: Obtaining access keys

After creating the IAM user, you’ll receive an Access Key ID and Secret Access Key. Keep these secure, as you’ll need them for configuration.

Step 3: Running aws configure command

Run the following command and enter your AWS credentials when prompted:

aws configure

You’ll need to provide:

  • AWS Access Key ID
  • AWS Secret Access Key
  • Default region name (e.g., us-west-2)
  • Default output format (json, yaml, text, or table)

Step 4: Understanding the configuration file

The aws configure command creates two files:

  • ~/.aws/credentials: Stores your AWS access keys
  • ~/.aws/config: Stores the default region and output format

You can edit these files manually if needed, but be cautious to maintain the correct format.

Testing AWS CLI Installation

To ensure your AWS CLI installation is working correctly, try running some basic commands:

aws s3 ls
aws ec2 describe-instances
aws iam list-users

These commands list your S3 buckets, EC2 instances, and IAM users, respectively. If you receive appropriate responses without errors, your AWS CLI is configured correctly and can communicate with AWS services.

Updating AWS CLI

Keeping your AWS CLI up-to-date is crucial for accessing the latest features and security updates. The update process depends on your installation method:

Updating AWS CLI installed via pip

If you installed AWS CLI using pip, update it with:

pip3 install --upgrade --user awscli

Updating AWS CLI installed via bundled installer

For installations using the bundled installer, follow these steps:

  1. Download the latest installer as described in the installation section
  2. Unzip the file
  3. Run the update command:
sudo ./aws/install --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli --update

Troubleshooting Common Issues

While installing and using AWS CLI on AlmaLinux 9, you might encounter some common issues. Here are solutions to a few of them:

Permission errors

If you encounter permission errors, ensure you’re using sudo for system-wide installations or the --user flag for user-specific installations.

Path issues

If the aws command is not found, you may need to add the installation directory to your PATH. Add the following line to your ~/.bashrc file:

export PATH=$PATH:$HOME/.local/bin

Dependency problems

If you face dependency issues, try installing the required packages:

sudo dnf install python3-devel

Best Practices for Using AWS CLI

To make the most of AWS CLI on AlmaLinux 9, consider these best practices:

Using named profiles

Create named profiles for different AWS accounts or roles:

aws configure --profile production

Use the profile with commands:

aws s3 ls --profile production

Enabling command completion

Enable command completion for easier use of AWS CLI:

complete -C '/usr/local/bin/aws_completer' aws

Add this line to your ~/.bashrc file for permanent effect.

Utilizing AWS CLI aliases

Create aliases for frequently used commands in your ~/.bashrc file:

alias awsls='aws ec2 describe-instances --query "Reservations[*].Instances[*].[InstanceId,State.Name,InstanceType]" --output table'

Congratulations! You have successfully installed AWS CLI. Thanks for using this tutorial for installing AWS CLI on the AlmaLinux 9 system. For additional help or useful information, we recommend you check the AWS CLI website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button