Automating AWS CLI v2 Installation: A Simplified Approach with Bash

π Introduction
In today's fast-paced tech environment, automating processes is key to efficiency. Managing cloud infrastructure via the AWS Command Line Interface (CLI) is no exception. π₯οΈ The following script offers an elegant solution for checking, installing, and verifying AWS CLI v2 on Linux systems. Letβs dive into the details. π§
π Why Automate the Installation?
Manually managing installations, particularly for crucial tools like AWS CLI, can be time-consuming and error-prone. π Automating this task ensures consistency across environments and eliminates the guesswork, making deployment faster and more reliable. β©
π Script Breakdown
Hereβs what this nifty script does, step by step:
π Check if AWS CLI v2 is Installed Before making any changes, the script checks if AWS CLI v2 is already installed. β If it detects the tool, a simple message confirms its presence.
π¦ Download AWS CLI v2 In the absence of AWS CLI v2, the script initiates its installation by downloading the required package from the official source. π This ensures the use of a trusted and updated version.
π οΈ Handle Dependencies The script checks if the
unzip
utility is installed. If not, it installsunzip
using the package manager (apt
). βοΈπ Install AWS CLI v2 Using the downloaded files, the script installs the AWS CLI v2 tool and verifies the installation to confirm success. π
π§Ή Clean Up To maintain a clutter-free environment, the script removes temporary files created during the process. π§½
π Logging and Feedback Each step is accompanied by clear and concise log messages, making it easier to track progress and troubleshoot if necessary. π
π₯οΈ The Script
bash
#!/bin/bash
# Check if AWS CLI v2 is installed
if aws --version 2>/dev/null | grep -q 'aws-cli/2'; then
echo "AWS CLI v2 is installed"
else
echo "Installing AWS CLI v2"
# Download AWS CLI v2
echo "Downloading AWS CLI v2"
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
# Install unzip if not already installed
if ! command -v unzip &> /dev/null; then
echo "Installing unzip"
sudo apt update
sudo apt install -y unzip
fi
# Unzip the downloaded file
echo "Unzipping AWS CLI v2"
unzip awscliv2.zip
# Install AWS CLI v2
echo "Installing AWS CLI v2"
sudo ./aws/install
# Clean up the downloaded files and unzipped folder
echo "Cleaning up"
rm -rf awscliv2.zip aws
# Verify the installation
echo "Installation complete"
aws --version
fi
π Why Use This Script?
π Efficiency: It automates repetitive installation tasks.
π‘οΈ Reliability: Ensures a proper, error-free installation process.
βοΈ Customization: Easily adaptable to specific requirements.
π― Conclusion
By integrating this script into your workflow, you can significantly enhance your deployment process. π Automation frees up valuable time, allowing developers and DevOps engineers to focus on more strategic tasks. π‘
Ready to streamline your AWS CLI installations? Try this script today and enjoy the power of automation!
Subscribe to my newsletter
Read articles from shrinivas joshi directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
