How to Configure AWS CLI
Amazon Web Services (AWS) provides a powerful command-line tool called the AWS Command Line Interface (AWS CLI) that allows users to manage cloud resources directly from a terminal. Instead of navigating through the AWS Management Console, you can control services, automate tasks, deploy infrastructure, and manage security using simple commands.
This guide walks you through everything you need to know to configure AWS CLI properly, including installation, authentication methods, profiles, security best practices, and troubleshooting.
How to Configure AWS CLI
What is the AWS CLI?
The AWS CLI is an open-source tool that enables you to interact with AWS services using commands in your command-line shell. With it, you can:
Launch EC2 instances
Manage S3 storage buckets
Configure IAM users and roles
Deploy cloud infrastructure
Automate DevOps workflows
It is widely used by cloud engineers, developers, system administrators, and DevOps professionals.
How to Configure AWS CLI
AWS CLI Versions
Before configuring, you should know that there are two major versions:
| Version | Status | Recommendation |
|---|---|---|
| AWS CLI v1 | Older | Not recommended for new installations |
| AWS CLI v2 | Latest | Recommended (better security & features) |
Always install AWS CLI version 2 unless you have legacy dependencies.
Installing AWS CLI
Windows
Download the AWS CLI v2 installer from the official AWS website.
Run the
.msiinstaller.Open Command Prompt and verify installation:
You should see output similar to:
macOS
Using Homebrew:
Or install via the official package installer.
Linux
Verify installation:
Understanding AWS Credentials
To use AWS CLI, you must authenticate using AWS credentials. These credentials are tied to an IAM (Identity and Access Management) user or role.
There are two key components:
| Credential | Description |
|---|---|
| Access Key ID | Public identifier for the IAM user |
| Secret Access Key | Private password-like key |
⚠️ Never share your secret key or upload it to public repositories.
How to Configure AWS CLI
Creating IAM User for CLI Access
It is not recommended to use your root AWS account. Instead:
Go to AWS Console → IAM → Users
Click Create user
Enable Programmatic access
Attach a policy (e.g., AdministratorAccess for learning, but use least privilege in production)
Download or copy the Access Key ID and Secret Access Key
How to Configure AWS CLI
Configuring AWS CLI (Basic Setup)
Run:
You will be prompted to enter:
Explanation of Each Field
| Field | Meaning |
|---|---|
| Access Key ID | Identifies your IAM user |
| Secret Access Key | Authenticates your requests |
| Region | Default AWS region (e.g., us-east-1, eu-west-1) |
| Output format | json, table, or text |
This creates two configuration files:
Credentials file
Config file
Using Named Profiles
You may want to manage multiple AWS accounts (e.g., dev, staging, production).
Create a named profile:
Now you can run commands like:
Profiles are stored like this:
credentials
config
Setting Default Region Without Reconfiguring
You can change the region directly:
Or for a specific profile:
Using Environment Variables (Alternative Method)
Instead of storing credentials in files, you can use environment variables.
Linux/macOS
Windows (PowerShell)
This method is useful in CI/CD pipelines.
Using AWS SSO (Single Sign-On)
Modern organizations use AWS IAM Identity Center (SSO).
Configure SSO:
You will provide:
SSO start URL
SSO region
Account ID
Role name
Then log in:
This method avoids long-term access keys and is much more secure.
Testing Your Configuration
Run:
If successful, you will see:
If you see an error, credentials are incorrect or permissions are missing.
How to Configure AWS CLI
Common Configuration Errors & Fixes
Error: Unable to locate credentials
Cause: AWS CLI cannot find credentials
Fix: Run aws configure again or check environment variables
Error: AccessDenied
Cause: IAM user lacks permissions
Fix: Attach required IAM policy
Error: InvalidClientTokenId
Cause: Wrong access key
Fix: Regenerate IAM access keys
How to Configure AWS CLI
Advanced Configuration Options
You can manually edit:
Example:
Disable CLI pager:
Security Best Practices
✅ Use IAM Roles instead of access keys (especially on EC2)
✅ Rotate access keys regularly
✅ Use MFA for sensitive accounts
❌ Never hard-code credentials in scripts
❌ Never commit .aws/credentials to Git
How to Configure AWS CLI
Using AWS CLI with MFA
For enhanced security:
This generates temporary credentials.
How to Configure AWS CLI
Automating Configuration in Scripts
Example Bash script:
Used in CI/CD systems like Jenkins, GitHub Actions, or GitLab CI.
Updating AWS CLI
Keep CLI updated:
Reinstall latest version if outdated.
How to Configure AWS CLI
Uninstalling AWS CLI
Windows
Remove from “Add or Remove Programs”
macOS/Linux
Key Takeaways
AWS CLI enables full cloud management from terminal
Always use IAM users or SSO — never root account
Profiles help manage multiple AWS environments
Environment variables are best for automation
Security should always be a top priority
How to Configure AWS CLI
Conclusion
Configuring the AWS CLI is one of the first essential skills in cloud computing. Once set up, it becomes a powerful tool for automation, DevOps workflows, infrastructure deployment, and daily cloud operations. Whether you’re managing S3 buckets, launching EC2 instances, or scripting deployments, mastering AWS CLI configuration gives you speed, control, and flexibility that the web console cannot match.
With proper configuration, secure credentials, and best practices, you can safely unlock the full power of AWS directly from your command line.


