Install and Configure AWS CLI¶
The AWS CLI is a command-line tool that enables users to manage AWS services directly from the command line, offering a flexible and efficient way to create, configure, and interact with AWS resources.
Let's see how you can install the AWS CLI on your operating system and configure it to access resources in AWS.
Warning
Given the ever-changing nature of the installation process, it is advisable to rely on the official documentation when installing AWS CLI.
You can visit the official documentation and follow the instructions to install or update the AWS CLI on your operating system.
Step 1: Install AWS CLI¶
Install AWS CLI on Mac¶
-
Download the installation file using the
curlcommand: -
Run the standard macOS installer program, specifying the downloaded
.pkgfile as the source: -
Verify the installation:
Install AWS CLI on Windows¶
-
Download and run AWS CLI MSI insatller
To install AWS CLI on Windows you can just download and run the AWS CLI MSI installer for Windows (64-bit).
-
Verify the installation:
Install AWS CLI on Linux x86 (64-bit)¶
-
Download the installation file:
-
Unzip the installer:
-
Run the installation program:
-
Verify the installation:
Install AWS CLI on Linux ARM¶
-
Download the installation file:
-
Unzip the installer:
-
Run the installation program:
-
Verify the installation:
Step 2: Configure AWS CLI¶
Just installing the AWS CLI won't grant you access to AWS resources. To interact with AWS services, you must configure it by providing your AWS credentials.
Below are the steps you can follow to configure the AWS CLI:
-
Create an AWS IAM user with programmatic access and download the access credentials (access key ID and secret access key).
-
Give the IAM user the necessary permissions. To keep it simple, we'll grant
Administratoraccess to the user.Warning
It's important to note that while we've simplified the process by granting
Administratoraccess for convenience, it's generally recommended to provide more granular and specific permissions to IAM users based on their actual needs. This helps reduce potential security risks and ensures a more controlled and secure environment. -
Configure the AWS CLI:
# Command template aws configure --profile <aws-profile-name> # Actual command aws configure --profile my-aws-accountYou'll be prompted to enter
AWS Access Key IDandAWS Secret Access Keyand the Defaultregionname this profile will use.Warning
If you don't specify the
--profileparameter, theAWS CLIwill use thedefaultprofile. To enhance configuration and security, it's advisable to use a named profile when configuring theAWS CLI.Using a named profile also enables you to configure multiple AWS accounts with different settings.
Step 3: Use AWS CLI to Access Resources in AWS¶
Now that we have configured the AWS CLI, let's explore how you can use it to access resources in your AWS account.
For instance, you can list S3 buckets using the following AWS CLI command:
You can also export the AWS_PROFILE environment variable and then call aws command without passing --profile parameter.
-
Export the
AWS_PROFILEenvironment variable: -
Run AWS CLI command: