AWS CLI Setup
Install the AWS Command Line Interface and configure it with your credentials for terminal-based AWS management.
What you'll accomplish
AWS CLI installed and configured, able to run AWS commands from your terminal
Prerequisites
- AWS account with IAM user (previous lesson)
- Access Key ID and Secret Access Key
Why Use the AWS CLI?
While the AWS Console (web interface) is great for exploration, the CLI is essential for:
- Automation - script deployments, backups, and maintenance
- Speed - many operations are faster from the terminal
- Reproducibility - commands can be saved and repeated
- AI-assisted workflows - Claude Code can run AWS commands for you
Step 1: Install AWS CLI
Note
If aws --version doesn't work, close your terminal completely and open a new one. The installer updates your PATH, but existing terminals won't see the change.
Step 2: Configure AWS CLI
Now we'll connect the CLI to your AWS account using the access keys you created in the previous lesson.
2.1 Run the Configuration Wizard
bashaws configure
You'll be prompted for four pieces of information:
2.2 Enter Your Credentials
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
Note
Finding your access keys: If you downloaded the CSV file when creating your IAM user, open it to find your keys. If you lost them, you'll need to create new keys in the IAM Console.
2.3 Choose Your Region
Pick a region close to you or your users:
| Region Code | Location | Good For |
|---|---|---|
us-east-1 | N. Virginia | Default, most services available first |
us-west-2 | Oregon | West coast US |
eu-west-1 | Ireland | Europe |
eu-central-1 | Frankfurt | Europe (Germany) |
ap-northeast-1 | Tokyo | Asia Pacific |
ap-southeast-1 | Singapore | Southeast Asia |
Note
Your region choice matters! Resources in different regions can't easily communicate, and some services cost more in certain regions.
Step 3: Verify Your Configuration
3.1 Check Your Identity
bashaws sts get-caller-identity
You should see something like:
json{ "UserId": "AIDAIOSFODNN7EXAMPLE", "Account": "123456789012", "Arn": "arn:aws:iam::123456789012:user/admin" }
This confirms the CLI is authenticated and shows which user you're acting as.
3.2 List S3 Buckets (Simple Test)
bashaws s3 ls
If you have no buckets, you'll see no output (that's fine!). If you see an error, something is wrong with your credentials.
3.3 Check Your Region
bashaws configure get region
Should output your chosen region (e.g., us-east-1).
Step 4: Understanding Configuration Files
The AWS CLI stores your credentials in two files:
Note
Never commit the ~/.aws/ folder to git! Add it to your global gitignore. These credentials provide full access to your AWS account.
Step 5: Multiple Profiles (Optional)
If you have multiple AWS accounts (personal, work, different projects), use named profiles:
Create a Named Profile
bashaws configure --profile work
Enter credentials for your work account.
Use a Named Profile
bash# Specify profile per-command aws s3 ls --profile work # Or set for your entire session export AWS_PROFILE=work # Linux/macOS $env:AWS_PROFILE="work" # Windows PowerShell
List Configured Profiles
bashaws configure list-profiles
Common CLI Commands Quick Reference
Now that you're set up, here are some useful commands:
bash# Get help for any command aws help aws s3 help aws ec2 describe-instances help # List resources aws s3 ls # List S3 buckets aws ec2 describe-instances # List EC2 instances aws ecr describe-repositories # List container registries # Get account info aws sts get-caller-identity # Who am I? aws iam list-users # List IAM users # Check service quotas aws service-quotas list-service-quotas --service-code ec2
Troubleshooting
"Unable to locate credentials"
bash# Check if credentials file exists ls -la ~/.aws/credentials # Reconfigure if needed aws configure
"Access Denied" Errors
Your IAM user may lack permissions. Check:
- You're using the correct profile
- Your IAM user has the required policies attached
- You're operating in the correct region
bash# Verify which identity you're using aws sts get-caller-identity
"Region is missing"
bash# Set your default region aws configure set region us-east-1 # Or specify per-command aws ec2 describe-instances --region us-west-2
Clock Skew Errors
AWS requires your system clock to be accurate. Fix with:
What's Next?
Your AWS CLI is now configured and ready. In the next lesson, we'll learn about AWS core concepts like regions, services, and how everything fits together before we deploy our first application.
Note
Checkpoint: Run aws sts get-caller-identity and confirm you see your account ID and IAM user ARN before continuing.