#GroundUp: Step-by-Step Guide to AWS CLI Installation
Hello all, and welcome to the third installment of my #GroundUp series, where I seek to share minute posts that I believe would be instrumental for anyone getting started with AWS. You can head over to this link to review the previous posts in the #GroundUp series.
Today we are talking about using the AWS CLI. There are multiple ways you can interact with Amazon Web Services (AWS), including the AWS Management Console, the AWS Command Line Interface (AWS CLI), and the AWS SDK. The AWS CLI is a powerful tool that allows you to manage your AWS resources directly from the command line. It allows for easy automation of repetitive tasks within your AWS environment.
In this blog post we will look at how to install and setup AWS CLI no matter the operating system you use.
Prerequisites
- An AWS Account (You can sign up here if you do not have that already — https://aws.amazon.com)
Part 1: Generating your Access Key and Secret Access Key
To get the access key ID and secret access key on AWS, you typically need to create an IAM (Identity and Access Management) user and generate access keys for that user. Refer to the previous post here to see how to create the IAM user. I will rehash and build on that as we go ahead.
Step 1: Sign in to the AWS Management Console.
1. Go to the AWS Management Console.
2. Sign in with your AWS account credentials.
3. In the AWS Management Console, open the “Services” menu and select “IAM” under the “Security, Identity, & Compliance” section.
Step 2: Generating Access and Secret Access Keys
1. In the IAM dashboard, click on “Users” in the left navigation pane.
2. Click on the username for which you want to create a new access key.
3. In the “User details” tab, navigate to the “Security credentials” tab.
4. Under the “Access keys” section, you will see existing access keys, if any.
5. Click on the “Create access key” button.
6. A pop-up will appear with the new Access Key ID and Secret Access Key.
Important: Download the CSV file containing the keys. This is the only opportunity to view or download the Secret Access Key.
7. Save the downloaded CSV file in a secure location. Do not share the secret access key.
8. If you have generated a new key to replace an existing one, consider deactivating or deleting the old key for security reasons.
Remember, the Secret Access Key is sensitive information, and AWS shows it only once during the key creation process. If you lose the keys, you’ll need to generate new ones. Always follow best practices for key management and security.
Step 2: Check if Python is Installed
AWS CLI requires Python to be installed, so let’s start by checking if Python is already installed on your system. Within your terminal or command prompt, enter the command below:
python --version
You can download Python if you have not already done so from here: https://www.python.org/downloads/
Step 3: Install AWS CLI
We can now go ahead and install the AWS CLI tool.
Installing on Windows
1. Download the AWS CLI installer for Windows from the website here.
2. Open the downloaded file and follow the on-screen instructions to complete the installation.
3. Run the command in your command prompt by running the command below to verify your installation.
aws --version
Installing on macOS
1. Download the AWSCLIV2.pkg file from here.
2. Follow the prompts to install AWSCLI on your macOS
3. Run command to verify installation
aws --version
Installing on Linux (v1)
Based on your distro, you can follow any of the following commands to install the AWS CLI v1
For Ubuntu/Debian
sudo apt update
sudo apt install awscli
For CentOS/RHEL
sudo yum install awscli
After the installation, verify the installation with the command:
aws - version
Installing on Linux (v2)
1. Download the AWS CLI v2 package from the website here.
2. Make sure to unzip the zip file and change it to the unzipped directory.
#note that the file name could be different
unzip awscli-exe-linux-x86_64.zip
cd aws
3. Run the install command
sudo ./aws/install
Step 4: Configure AWS CLI
After installation is complete, you need to set your AWS credentials.
1. Run the following command:
aws configure
2. You will be prompted to enter your access key and secret access key, default region, and default output format.
3. After providing this information, your AWS CLI is configured and ready to use.
Step 5: Verify Your Installation
You can run a simple AWS CLI command to verify the configuration is done properly.
aws s3 ls
If the setup worked fine you should be able to see a list of S3 buckets within your account for this command. If you do not have any buckets created in your account, you can go ahead and create a test bucket.
Congratulations! You’ve successfully installed and configured the AWS CLI.
Conclusion
Installing the AWS CLI is a crucial step to getting started on Amazon Web Services, where you can automate your workflow. If you have any issues, you can reach out or consult the AWS CLI documentation here.
Thanks for reading, and I hope this helps you easily set up your account. Do keep an eye out for my upcoming post in the #GroundUp series.
References
- AWS Command Line Interface — https://aws.amazon.com/cli/
- AWS Access Keys Guide— https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html
- AWS CLI Reference Guide — https://docs.aws.amazon.com/cli/latest/reference/