Overview
This guide covers common errors you may encounter when runningiam-audit, along with diagnostic steps and solutions. Most errors are related to AWS permissions, role configuration, or API throttling.
Permission Errors
AccessDenied: Not authorized to perform sts:AssumeRole
AccessDenied: Not authorized to perform sts:AssumeRole
AccessDenied: organizations:ListAccounts
AccessDenied: organizations:ListAccounts
NoSuchEntity: The user with name X cannot be found
NoSuchEntity: The user with name X cannot be found
Role Assumption Failures
Error assuming role: The security token included in the request is invalid
Error assuming role: The security token included in the request is invalid
Error Message
Cause
The AWS credentials for your--profile are invalid, expired, or missing.Diagnosis
1. Check if credentials are configured:Solution
Option 1: Reconfigure the profile~/.aws/credentials with the temporary credentials.Role assumption succeeds but IAM calls fail
Role assumption succeeds but IAM calls fail
CloudTrail Errors
Error querying CloudTrail: AccessDenied on cloudtrail:LookupEvents
Error querying CloudTrail: AccessDenied on cloudtrail:LookupEvents
No CloudTrail events found (Total: 0)
No CloudTrail events found (Total: 0)
Observation
Possible Causes
- No IAM events occurred in the date range
- CloudTrail is not enabled in the accounts
- Events are older than CloudTrail retention (90 days default)
- The hardcoded start date is too recent (iam_audit.py:137)
Diagnosis
1. Check if CloudTrail is enabled:Solution
Option 1: Modify the start date in iam_audit.py:API Throttling
Throttling: Rate exceeded (IAM API)
Throttling: Rate exceeded (IAM API)
Error Message
Cause
Too many IAM API calls in a short time. The script makes 4 API calls per IAM user:list_access_keyslist_mfa_devicesget_login_profileget_access_key_last_used
Solution
Option 1: Add exponential backoff (recommended)Modify the script to use adaptive retry mode:Throttling: Rate exceeded (CloudTrail API)
Throttling: Rate exceeded (CloudTrail API)
Error Message
Cause
CloudTraillookup_events is limited to 2 requests per second per account.The script queries 5 event types per account, which can trigger throttling in large organizations.Solution
Option 1: Add delays between event queriesEmpty or Missing Report
No CSV file generated
No CSV file generated
Observation
iam_audit_report_*.csv file is created.Cause
Thefindings list is empty. This happens when:- No IAM users have access keys (ideal state)
- All accounts were skipped due to role assumption errors
- Organizations API call failed
Diagnosis
1. Check if accounts were processed:Look for console output like:Solution
If accounts were skipped: Fix role assumption errors (see Permission Errors section)If no IAM users have keys: This is good! It means you’re following AWS best practices (use roles, not access keys).To verify the script works: Create a test IAM user with an access key in one account:CSV file is empty (only headers)
CSV file is empty (only headers)
Observation
The CSV file exists but contains only headers:Cause
No IAM users with access keys were found across all accounts.Solution
This is likely the correct result. Modern AWS best practices recommend:- ✅ Use IAM roles with temporary credentials (STS)
- ✅ Use AWS IAM Identity Center (SSO)
- ❌ Avoid long-term access keys
- Verify the script ran on all accounts (check console output)
- Manually check a few accounts for IAM users:
Profile and Configuration Issues
ProfileNotFound: The config profile could not be found
ProfileNotFound: The config profile could not be found
RegionNotFound: You must specify a region
RegionNotFound: You must specify a region
Script Execution Errors
ModuleNotFoundError: No module named 'boto3'
ModuleNotFoundError: No module named 'boto3'
Script hangs or runs indefinitely
Script hangs or runs indefinitely
Observation
The script appears to freeze after:Cause
Likely API throttling without proper retry logic, or the script is processing a large number of IAM users.Diagnosis
Add verbose logging:Solution
Option 1: Add a timeout to boto3 clientGetting Help
Check AWS CloudTrail Logs
If you’re still encountering issues, check CloudTrail for API call errors:errorCode or errorMessage fields.
Enable Debug Logging
Modify the script to enable debug output:Community Support
- Full error message
- AWS region
- Number of accounts in your organization
- Relevant CloudTrail logs
AWS Support Resources
- AWS STS AssumeRole Documentation
- AWS IAM Troubleshooting
- CloudTrail LookupEvents API
- Boto3 Error Handling
Quick Diagnostic Checklist
Before opening an issue, verify:- AWS CLI profile exists:
aws configure list-profiles - Profile has valid credentials:
aws sts get-caller-identity --profile <profile> - Management account can list accounts:
aws organizations list-accounts --profile <profile> - Target role exists:
aws iam get-role --role-name <role> --profile <target-account> - Trust policy allows management account: Check
AssumeRolePolicyDocument - Role has required IAM permissions: Check attached policies
- boto3 is installed:
python3 -c "import boto3" - Python version is 3.9+:
python3 --version
