AWS CLI Getting Started: Install, Configure, and Run Commands

The AWS Command Line Interface (CLI) is one of the most powerful tools in any AWS engineer's toolkit. Instead of clicking through the AWS Management Console, you can manage hundreds of resources with a single command, automate complex workflows in shell scripts, and integrate AWS operations into CI/CD pipelines. This guide covers everything you need to get started with the AWS CLI from scratch.

What Is the AWS CLI?

The AWS CLI is an open-source tool that lets you interact with AWS services directly from your terminal. Every action you can take in the AWS Console can also be performed via the CLI — and many things, like bulk operations, scripting, and automation, are only practical through the CLI or SDKs.

Installing the AWS CLI

Linux / Amazon Linux

# Download and install AWS CLI v2
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

# Verify installation
aws --version
# Output: aws-cli/2.x.x Python/3.x.x Linux/...

macOS

# Using Homebrew
brew install awscli

# Or download the pkg installer from https://awscli.amazonaws.com/AWSCLIV2.pkg
aws --version

Windows

# Using winget
winget install Amazon.AWSCLI

# Or download the MSI installer from the AWS documentation
aws --version

Configuring the AWS CLI

Run aws configure to set up your credentials and default region. You'll need an IAM user's access key ID and secret access key:

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

This creates two files: ~/.aws/credentials (stores keys) and ~/.aws/config (stores region and output format).

Using Named Profiles

If you work with multiple AWS accounts, use named profiles:

# Configure a named profile for a staging account
aws configure --profile staging

# Use the profile for a specific command
aws s3 ls --profile staging

# Set a default profile for the session
export AWS_PROFILE=staging

Essential AWS CLI Commands

S3 Operations

# List all buckets
aws s3 ls

# Upload a file
aws s3 cp ./app.zip s3://my-bucket/releases/app.zip

# Sync a directory to S3
aws s3 sync ./dist/ s3://my-bucket/website/ --delete

# Download a file
aws s3 cp s3://my-bucket/releases/app.zip ./app.zip

EC2 Operations

# List running instances with their IDs and public IPs
aws ec2 describe-instances 
  --filters "Name=instance-state-name,Values=running" 
  --query "Reservations[*].Instances[*].[InstanceId,PublicIpAddress,Tags[?Key=='Name'].Value|[0]]" 
  --output table

# Start and stop an instance
aws ec2 start-instances --instance-ids i-0abcd1234efgh5678
aws ec2 stop-instances --instance-ids i-0abcd1234efgh5678

IAM Operations

# List all IAM users
aws iam list-users --output table

# Get the current caller identity (who am I?)
aws sts get-caller-identity

Lambda Operations

# List all Lambda functions
aws lambda list-functions --query "Functions[*].[FunctionName,Runtime,LastModified]" --output table

# Invoke a function and capture output
aws lambda invoke 
  --function-name my-function 
  --payload '{"key": "value"}' 
  --cli-binary-format raw-in-base64-out 
  output.json

Output Formats and Filtering with JMESPath

The AWS CLI supports four output formats: json, yaml, table, and text. Use the --query flag with JMESPath expressions to filter output:

# Get only the AMI ID of an instance
aws ec2 describe-instances 
  --instance-ids i-0abcd1234efgh5678 
  --query "Reservations[0].Instances[0].ImageId" 
  --output text

# List all S3 bucket names as plain text
aws s3api list-buckets --query "Buckets[*].Name" --output text

Using AWS CLI with IAM Roles (No Hardcoded Keys)

On EC2 instances, Lambda functions, or ECS tasks with attached IAM roles, the CLI automatically retrieves temporary credentials from the instance metadata service. No aws configure needed:

# This works automatically on EC2 with an IAM role attached
aws s3 ls  # Uses the role's permissions, no keys needed

CLI Pagination

Some commands return paginated results. Use --no-paginate to get all results in one call, or --page-size to control how many results per API call:

# Get all EC2 instances across all pages
aws ec2 describe-instances --no-paginate

Summary

The AWS CLI is the fastest way to interact with AWS for automation, scripting, and day-to-day operations. Master the core commands for the services you use most, learn JMESPath filtering for clean output, and use named profiles to manage multiple accounts. Once you are comfortable with the CLI, pair it with shell scripts or tools like AWS CDK and Terraform to manage infrastructure at scale.