A command-line tool to list all AWS profiles, check their credential status, and refresh IAM user access keys.
- π 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
- 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
pip install aws-profileraws-profilerThe 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 credentials for a specific IAM user or SSO profile:
aws-profiler --refresh myprofileFor 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
To also delete the old access key from AWS after creating the new one:
aws-profiler --refresh myprofile --deleteAutomatically refresh credentials for ALL IAM users and SSO profiles:
aws-profiler --refresh --allThis 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π 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
π 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.
π 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"
π 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
- β 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
- User: IAM user with permanent access keys (can be refreshed)
- Role: Assumed role with temporary credentials (cannot be refreshed)
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.
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}"
}
]
}Ensure AWS credentials exist in ~/.aws/credentials or set environment variables:
export AWS_ACCESS_KEY_ID=your_key
export AWS_SECRET_ACCESS_KEY=your_secretVerify your IAM user has the required permissions listed above. Check your IAM policy allows iam:CreateAccessKey and iam:ListAccessKeys.
- 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/
AWS limits IAM users to 2 access keys. Delete an old key manually or use the --delete flag when refreshing.
Ensure ~/.aws/backups/ directory exists and is writable. The tool will attempt to create it automatically with 700 permissions.
β οΈ 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
MIT License
Contributions are welcome! Please feel free to submit a Pull Request.