IAMdata Python Library
IAMdata provides comprehensive AWS IAM data for actions, resources, and conditions, based on official IAM policy documents. It ensures data freshness by checking for updates daily. This library is useful for security tools, policy analysis, and compliance checks, providing a programmatic way to access detailed IAM information.
Common errors
-
AttributeError: 'NoneType' object has no attribute 'get' (or similar errors when accessing properties)
cause A lookup method (e.g., `get_action`, `get_resource_type`) returned `None` because the requested item was not found, and subsequent code attempted to access properties of this `None` object.fixAlways check if the result of a lookup method is `None` before attempting to access its attributes or dictionary items. For example: `data = iam_data.get_action('s3', 'NonExistentAction'); if data: print(data['description'])`. -
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response')) OR URLError: <urlopen error ...>cause The library failed to connect to its external data source (GitHub) to download updates, likely due to a lack of internet connectivity, a firewall block, or temporary network issues.fixVerify your internet connection and ensure that no firewalls or proxy settings are preventing Python from making outbound HTTP/HTTPS requests to `github.com`. -
KeyError: 'some_field' (when accessing dictionary-like objects returned by the library)
cause Attempting to access a field within an IAM data object that either does not exist, or its name has changed due to an upstream IAM data update.fixUse the `.get()` method with a default value for dictionary-like access (e.g., `item.get('description', 'N/A')`) to prevent `KeyError`. Consult AWS IAM documentation or the `iamdata` object structure for available fields.
Warnings
- gotcha The library's versioning (`0.1.YYYYMMDD1`) indicates it's still pre-1.0, and while core API methods are generally stable, minor API changes could occur in new date-stamped versions. Pin exact versions for production use to ensure stability.
- gotcha IAMdata relies on daily updates of external AWS IAM data. This means the *content* of the returned data (e.g., descriptions, condition keys, ARN patterns) can change over time without a library code update. Logic dependent on specific IAM data values might need periodic review.
- gotcha The library requires internet access to fetch and update its internal IAM data cache. While subsequent operations can be performed offline with cached data, the initial load and daily updates will fail without connectivity.
Install
-
pip install iamdata
Imports
- IAMData
from iamdata import IAMData
Quickstart
from iamdata import IAMData
# Initialize the IAMData object, which will ensure data is up-to-date
iam_data = IAMData()
# Get details for a specific S3 action
s3_get_object_data = iam_data.get_action("s3", "GetObject")
if s3_get_object_data:
print(f"S3 GetObject: {s3_get_object_data.get('description')}")
else:
print("S3 GetObject not found.")
# Get all actions for the S3 service
s3_actions = iam_data.get_service_actions("s3")
if s3_actions:
print(f"Number of S3 actions: {len(s3_actions)}")
# Get details for an EC2 resource type
ec2_instance_data = iam_data.get_resource_type("ec2", "instance")
if ec2_instance_data:
print(f"EC2 Instance resourceARN: {ec2_instance_data.get('resourceARN')}")