AWS CLI Setup
Install and configure the AWS Command Line Interface
The AWS Command Line Interface (CLI) is a unified tool to manage your AWS services from the command line.
Prerequisites
You'll need an AWS account and IAM credentials before configuring the CLI.
Installation
brew install awscliOr download the official installer:
curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
sudo installer -pkg AWSCLIV2.pkg -target /curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/installFor ARM-based systems:
curl "https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/installmsiexec.exe /i https://awscli.amazonaws.com/AWSCLIV2.msiOr download from the AWS CLI page.
Configuration
Run Configuration Wizard
aws configureYou'll be prompted for:
- AWS Access Key ID: Your access key
- AWS Secret Access Key: Your secret key
- Default region name: e.g.,
us-east-1 - Default output format:
json,yaml,text, ortable
Verify Configuration
aws sts get-caller-identityExpected output:
{
"UserId": "AIDAEXAMPLEID",
"Account": "123456789012",
"Arn": "arn:aws:iam::123456789012:user/username"
}Named Profiles
Create multiple profiles for different environments:
# Configure a named profile
aws configure --profile production
# Use a named profile
aws s3 ls --profile production
# Set default profile
export AWS_PROFILE=productionConfiguration Files
AWS CLI stores configuration in two files:
config
credentials
[default]
aws_access_key_id = YOUR_ACCESS_KEY
aws_secret_access_key = YOUR_SECRET_KEY
[production]
aws_access_key_id = PROD_ACCESS_KEY
aws_secret_access_key = PROD_SECRET_KEY[default]
region = us-east-1
output = json
[profile production]
region = us-west-2
output = yamlSecurity
Never commit AWS credentials to version control. Use environment variables or AWS profiles instead.
Verify Installation
aws --versionCommon Options
| Option | Description |
|---|---|
--profile | Use a specific profile |
--region | Override the default region |
--output | Output format (json, yaml, text, table) |
--query | JMESPath query for filtering output |
--dry-run | Check permissions without making changes |
Environment Variables
export AWS_ACCESS_KEY_ID="your-access-key"
export AWS_SECRET_ACCESS_KEY="your-secret-key"
export AWS_DEFAULT_REGION="us-east-1"export AWS_PROFILE="production"Credential Precedence
AWS CLI uses credentials in this order: CLI options → Environment variables → Config files → Instance metadata (EC2/ECS).