Installing & Configuring the AWS CLI

The AWS CLI lets you control AWS from your terminal. Install it, then run aws configure to store your credentials.

Syntaxaws <service> <action> [--options]

The AWS Command Line Interface (CLI) is a single tool that talks to every AWS service. Once configured, commands follow the pattern aws <service> <action> [options].

1. Install

Download the AWS CLI v2 installer for your operating system from the AWS docs, or use a package manager. Verify it with aws --version.

2. Configure

Run aws configure and paste in an access key ID and secret access key (created in IAM), plus a default Region and output format. These are saved to ~/.aws/credentials and ~/.aws/config.

3. Profiles

Use named profiles to switch between accounts: aws configure --profile work, then add --profile work to any command.

Example

Example · bash
# Configure the CLI interactively
aws configure
# AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
# AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
# Default region name [None]: us-east-1
# Default output format [None]: json

# Verify it works — this should print your account and user ARN
aws sts get-caller-identity

When to use it

  • A DevOps engineer installs the AWS CLI on a CI/CD build agent to automate Lambda deployments from a pipeline without the Console.
  • A developer configures named profiles with 'aws configure --profile dev' to switch between development and production accounts instantly.
  • A security team member runs 'aws configure' on a new workstation to connect their local environment to a company AWS account.

More examples

Install AWS CLI v2 on Linux

Downloads and installs the official AWS CLI v2 on Linux and confirms the installation with a version check.

Example · bash
curl -fsSL "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o awscliv2.zip
unzip awscliv2.zip
sudo ./aws/install
aws --version

Configure Default Credentials

Runs interactive configuration to store credentials and defaults in ~/.aws/credentials and ~/.aws/config.

Example · bash
aws configure
# Prompts:
# AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
# AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
# Default region name [None]: us-east-1
# Default output format [None]: json

Use Named Profiles for Multi-Account

Creates a named CLI profile for a separate account and shows how to activate it per-command or session-wide.

Example · bash
# Set up a named profile for staging
aws configure --profile staging

# Use it for one command
aws s3 ls --profile staging

# Set it as the session default
export AWS_PROFILE=staging
aws ec2 describe-instances

Discussion

  • Be the first to comment on this lesson.