A CLI tool to list AWS profiles and check their credential status
Project description
AWS Profiler
A command-line tool to list all AWS profiles, check their credential status, and refresh IAM user access keys.
Features
- ๐ Lists all AWS profiles from
~/.aws/credentialsand~/.aws/config - ๐ Retrieves account information for each profile
- โ Checks if credentials are active or expired
- โฑ๏ธ Shows credential age and expiration time
- ๐ Automatically refreshes IAM user access keys
- ๐พ Backs up old credentials before rotation
- ๐๏ธ Optionally deletes old keys from AWS
- ๐ Displays results in a formatted table
- ๐ Provides summary statistics
Prerequisites
- Python 3.8, 3.9, 3.10, 3.11, or 3.12
- AWS CLI configured (v2 recommended for SSO support)
- Required Python packages:
boto3 >= 1.26.0tabulate >= 0.9.0python-dateutil
Installation
pip install aws-profiler
Usage
List all profiles and check status
aws-profiler
The tool will scan your AWS configuration files and display a table with:
- Profile name
- Account ID
- User/Role name
- Credential type (User/Role)
- Status (Active/Expired/Error)
- Credential age (how old the credentials are)
- Expiration time (for temporary credentials)
Refresh specific profile
Refresh credentials for a specific IAM user or SSO profile:
aws-profiler --refresh myprofile
For IAM Users, this will:
- Verify the profile is an IAM user (not a role)
- Create a new access key
- Backup the old credentials to
~/.aws/backups/ - Update the credentials file with the new key
- Keep the old key active in AWS (unless
--deleteis used)
For SSO Profiles, this will:
- Detect the profile is SSO-configured
- Run
aws sso login --profile <name> - Open your browser for authentication
- Complete the SSO flow through AWS CLI
Refresh and delete old key (IAM users only)
To also delete the old access key from AWS after creating the new one:
aws-profiler --refresh myprofile --delete
โ ๏ธ Warning: This will permanently delete the old access key from AWS. You'll be prompted for confirmation.
Refresh all eligible profiles
Automatically refresh credentials for ALL IAM users and SSO profiles:
aws-profiler --refresh --all
This will:
- Scan all profiles and identify eligible ones (IAM users and SSO)
- Show summary of what will be refreshed
- Ask for confirmation
- Refresh all IAM user keys (with backups)
- Trigger SSO login for all SSO profiles
To also delete old keys from AWS for all IAM users:
aws-profiler --refresh --all --delete
Example Output
Listing profiles
๐ AWS Profile Status Checker
================================================================================
๐ Found 3 profile(s)
Checking default... [โ Active]
Checking staging... [โ Active]
Checking production... [โ Expired]
โโโโโโโโโโโโโโโคโโโโโโโโโโโโโโโคโโโโโโโโโโโโโคโโโโโโโโโคโโโโโโโโโโโโคโโโโโโโโคโโโโโโโโโโโโโ
โ Profile โ Account ID โ User/Role โ Type โ Status โ Age โ Expires In โ
โโโโโโโโโโโโโโโชโโโโโโโโโโโโโโโชโโโโโโโโโโโโโชโโโโโโโโโชโโโโโโโโโโโโชโโโโโโโโชโโโโโโโโโโโโโก
โ default โ 123456789012 โ admin โ User โ โ Active โ 15d 3hโ Permanent โ
โโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโผโโโโโโโโโโโโโผโโโโโโโโโผโโโโโโโโโโโโผโโโโโโโโผโโโโโโโโโโโโโค
โ staging โ 234567890123 โ dev-role โ Role โ โ Active โ 2h โ 10h 45m โ
โโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโผโโโโโโโโโโโโโผโโโโโโโโโผโโโโโโโโโโโโผโโโโโโโโผโโโโโโโโโโโโโค
โ production โ N/A โ N/A โ N/A โ โ Expired โ N/A โ Expired โ
โโโโโโโโโโโโโโโงโโโโโโโโโโโโโโโงโโโโโโโโโโโโโงโโโโโโโโโงโโโโโโโโโโโโงโโโโโโโโงโโโโโโโโโโโโโ
๐ Summary: โ 2 active | โ 1 expired | โ 0 error/no credentials
Refreshing a single IAM user
๐ AWS Credential Refresh
================================================================================
๐ Refreshing credentials for profile: myprofile
โ
Success!
โ Credentials refreshed successfully for profile "myprofile"
New Key: AKIAIOSFODNN7EXAMPLE
Backup: /Users/username/.aws/backups/credentials_backup_myprofile_DEXAMPLE_20251124_143022
Old key AKIAIOSFODNN6EXAMPLE is still active in AWS. Use --delete to remove it.
Refreshing an SSO profile
๐ AWS Credential Refresh
================================================================================
๐ Refreshing credentials for profile: sso-dev
๐ Initiating SSO login for profile: sso-dev
Please follow the instructions in your browser...
Attempting to automatically open the SSO authorization page in your default browser.
If the browser does not open or you wish to use a different device to authorize this request, open the following URL:
https://device.sso.us-east-1.amazonaws.com/
Then enter the code: ABCD-EFGH
โ
Success!
โ SSO login successful for profile "sso-dev"
Refreshing all profiles
๐ AWS Credential Refresh - ALL PROFILES
================================================================================
๐ Analyzing profiles...
IAM Users (can refresh): 2
SSO Profiles (can refresh): 1
Roles (cannot refresh): 1
Inactive/Error profiles: 0
Will refresh 2 IAM user(s) and 1 SSO profile(s)
Type 'yes' to continue: yes
================================================================================
๐ Refreshing IAM User Profiles:
โ dev-user...
โ Success
โ prod-user...
โ Success
๐ Refreshing SSO Profiles:
โ sso-dev...
[SSO login flow continues...]
โ Success
================================================================================
๐ Summary: โ 3 refreshed | โ 0 failed
Status Values
- โ Active: Credentials are valid and working
- โ Expired: Token or credentials have expired
- โ No Creds: Profile exists but no credentials are configured
- โ Invalid: Other authentication or authorization errors
Credential Types
- User: IAM user with permanent access keys (can be refreshed)
- Role: Assumed role with temporary credentials (cannot be refreshed)
Backup Files
When refreshing credentials, the old credentials are automatically backed up to:
~/.aws/backups/credentials_backup_<profile>_<key-suffix>_<timestamp>
Backup files are created with restricted permissions (600) for security.
IAM Permissions Required for Refresh
To use the refresh functionality, your IAM user needs these permissions:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iam:CreateAccessKey",
"iam:ListAccessKeys",
"iam:DeleteAccessKey"
],
"Resource": "arn:aws:iam::*:user/${aws:username}"
}
]
}
Troubleshooting
"No credentials found" error
Ensure AWS credentials exist in ~/.aws/credentials or set environment variables:
export AWS_ACCESS_KEY_ID=your_key
export AWS_SECRET_ACCESS_KEY=your_secret
"Access Denied" when refreshing
Verify your IAM user has the required permissions listed above. Check your IAM policy allows iam:CreateAccessKey and iam:ListAccessKeys.
SSO login fails
- Ensure AWS CLI v2 is installed:
aws --version - Verify SSO configuration in
~/.aws/config:[profile sso-profile] sso_start_url = https://your-domain.awsapps.com/start sso_region = us-east-1 sso_account_id = 123456789012 sso_role_name = YourRoleName
- Clear cached SSO tokens:
rm -rf ~/.aws/sso/cache/
"Maximum number of access keys exceeded"
AWS limits IAM users to 2 access keys. Delete an old key manually or use the --delete flag when refreshing.
Backup directory permission errors
Ensure ~/.aws/backups/ directory exists and is writable. The tool will attempt to create it automatically with 700 permissions.
Security Considerations
- โ ๏ธ Backup files contain plaintext credentials - secure these files appropriately
- ๐ Backup files are created with 600 permissions (owner read/write only)
- ๐๏ธ Old access keys remain in AWS backups - consider rotating or deleting them
- ๐ For production workloads, consider using AWS Secrets Manager or Systems Manager Parameter Store
- ๐ก๏ธ Regularly audit and rotate your access keys
- ๐ Use IAM roles with temporary credentials when possible instead of long-term keys
License
MIT License
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aws_profiler-1.1.1.tar.gz.
File metadata
- Download URL: aws_profiler-1.1.1.tar.gz
- Upload date:
- Size: 23.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91603d45b934133c7d8c5c6ab48878ca6d1a9ec924ff29d38627d1d6637543cb
|
|
| MD5 |
b53bb53f07ba4dda2b14de06c90c91f8
|
|
| BLAKE2b-256 |
0db6505c53a4568e8b6ba1694ec5df824a1ed1d998c5d9df70dff9676f83b2b9
|
File details
Details for the file aws_profiler-1.1.1-py3-none-any.whl.
File metadata
- Download URL: aws_profiler-1.1.1-py3-none-any.whl
- Upload date:
- Size: 25.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4045738682121d6a15cfe3be261941ad3336b2315243cfb0618ac96197267dd4
|
|
| MD5 |
ff7671780979afbdf30936a86ababc63
|
|
| BLAKE2b-256 |
652256f269843f75f51f0ae386f6f8719a202c8c03dc08bc17070e4c3c2dead2
|