Synopsis
Required Arguments
Both arguments are mandatory. The tool will exit with an error if either is missing.AWS CLI profile name configured in
~/.aws/credentials or ~/.aws/configThis profile must have access to the management account of your AWS Organization with permissions to:organizations:ListAccountssts:AssumeRoleinto member accounts
The profile name must exactly match a configured AWS CLI profile. Use
aws configure list-profiles to see available profiles.Name of the IAM role to assume in each member accountThis role must:
- Exist in all member accounts you want to audit
- Have a trust policy allowing the management account to assume it
- Have IAM and CloudTrail read permissions
Usage Examples
Basic Audit
Running from Different Directory
Using Python Virtual Environment
Exit Codes
The script does not implement custom exit codes. Standard Python behavior applies:| Exit Code | Meaning |
|---|---|
0 | Success |
1 | Unhandled exception |
2 | Command-line argument error (missing required flags) |
Environment Variables
The tool respects standard AWS SDK environment variables:Default AWS profile to use if
--profile is not specifiedDefault AWS region for API calls
IAM is a global service. CloudTrail queries are performed in us-east-1 regardless of this setting (hardcoded at
iam_audit.py:96).AWS access key ID (not recommended; use profiles instead)
AWS secret access key (not recommended; use profiles instead)
Output Files
The tool generates two CSV files in the current working directory:| File Pattern | Description |
|---|---|
iam_audit_report_YYYYMMDD_HHMMSS.csv | IAM users, access keys, MFA status, and console access |
cloudtrail_events_YYYYMMDD_HHMMSS.csv | CloudTrail events for IAM user and key lifecycle tracking |
YYYYMMDD_HHMMSS (e.g., 20260305_143022)
Files are created in the directory where you run the command, not where the script is located.
Standard Output
The tool prints progress and summary information to stdout:Standard Error
Errors for specific accounts are printed to stdout (not stderr) and the audit continues:Required IAM Permissions
Management Account Profile
The profile specified with--profile needs:
Member Account Role
The role specified with--role needs in each member account:
Session Names
The tool uses two different session names when assuming roles:| Session Name | Used For | Source Line |
|---|---|---|
SecurityAudit | IAM data collection | iam_audit.py:154 |
CloudTrailAudit | CloudTrail event queries | iam_audit.py:93 |
Session names appear in CloudTrail logs, making it easy to identify audit activity.
Hardcoded Values
Be aware of these hardcoded values in the current version:| Value | Location | Purpose |
|---|---|---|
2026-02-18 | iam_audit.py:137 | CloudTrail events start date |
us-east-1 | iam_audit.py:96 | CloudTrail query region |
['DeleteUser', 'DeleteAccessKey', 'DeleteLoginProfile', 'CreateAccessKey', 'CreateUser'] | iam_audit.py:88 | CloudTrail event names to query |
Next Steps
Running an Audit
Step-by-step guide to executing an audit
Understanding Reports
Learn how to analyze the generated CSV files
