Skip to main content

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/credentials and ~/.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

Installation

Install from source

pip install -e .

Install from PyPI (when published)

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:

  1. Verify the profile is an IAM user (not a role)
  2. Create a new access key
  3. Backup the old credentials to ~/.aws/backups/
  4. Update the credentials file with the new key
  5. Keep the old key active in AWS (unless --delete is used)

For SSO Profiles, this will:

  1. Detect the profile is SSO-configured
  2. Run aws sso login --profile <name>
  3. Open your browser for authentication
  4. 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

Or simply:

aws-profiler --refresh

This will:

  1. Scan all profiles and identify eligible ones (IAM users and SSO)
  2. Show summary of what will be refreshed
  3. Ask for confirmation
  4. Refresh all IAM user keys (with backups)
  5. 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.

Requirements

  • Python 3.8+
  • AWS credentials configured in ~/.aws/credentials or ~/.aws/config
  • For refresh functionality: IAM permissions to create and optionally delete access keys

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}"
    }
  ]
}

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aws_profiler-1.1.0.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aws_profiler-1.1.0-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file aws_profiler-1.1.0.tar.gz.

File metadata

  • Download URL: aws_profiler-1.1.0.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for aws_profiler-1.1.0.tar.gz
Algorithm Hash digest
SHA256 f35222ce033db49bf1f1921387feceb32659df17df1581880957d76c43651823
MD5 f21b56867814f8fcd15fb2b7b9d3d420
BLAKE2b-256 c5b9ddcd17a4b74832a1c7baffba6f403ab8997949d6c53055361c36a2d7a3eb

See more details on using hashes here.

File details

Details for the file aws_profiler-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: aws_profiler-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for aws_profiler-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 239edfd2a309e9c3fd092db04edbe806e354d2430a7950bb5393770d6105299b
MD5 bd93d4942446dc09e0e616b6493e8de5
BLAKE2b-256 0181b221de43dc826109011f96d1c92d8e32b3532d1ebe2b61e72411736a44c3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page