arn
raw JSON → 0.1.5 verified Mon Apr 27 auth: no python
A lightweight Python library for parsing and manipulating AWS ARNs (Amazon Resource Names). Version 0.1.5, low activity.
pip install arn Common errors
error AttributeError: module 'arn' has no attribute 'ARN' ↓
cause Importing the module instead of the class.
fix
Use 'from arn import ARN' or 'import arn; arn.ARN'.
error arn.ArnException: Invalid ARN string ↓
cause The input string does not match the ARN format (e.g., missing 'arn:' prefix).
fix
Ensure the string starts with 'arn:' and follows the pattern 'arn:partition:service:region:account:resource'.
Warnings
gotcha The ARN constructor does not validate that the partition matches known AWS partitions (e.g., 'aws', 'aws-cn', 'aws-us-gov'). It accepts arbitrary strings, so 'arn:foo:...' parses without error. ↓
fix Validate partition manually with a whitelist if needed.
gotcha The library does not support ARNs with resource qualifiers (like 'arn:aws:s3:::bucket/key') via the standard resource attribute; you may need to parse the resource string manually. ↓
fix Use `parsed.resource` and split on '/' or ':' as needed.
Imports
- ARN wrong
import arncorrectfrom arn import ARN
Quickstart
from arn import ARN
arn_str = os.environ.get('AWS_ARN', 'arn:aws:iam::123456789012:user/JohnDoe')
try:
parsed = ARN(arn_str)
print(f'Service: {parsed.service}, Region: {parsed.region}, Account: {parsed.account}, Resource: {parsed.resource}')
except Exception as e:
print(f'Invalid ARN: {e}')