AWS IP Ranges
raw JSON → 0.3.3 verified Mon Apr 27 auth: no python
AWS IP Ranges is a Python library for working with AWS IP address ranges natively. It provides tools to download, parse, and query the AWS IP address ranges JSON data (from https://ip-ranges.amazonaws.com/ip-ranges.json). Current version is 0.3.3, released periodically.
pip install awsipranges Common errors
error NameError: name 'AWSIPPrefixes' is not defined ↓
cause Importing incorrectly (e.g., `import awsipranges` and then `awsipranges.AWSIPPrefixes` without the class import), or package not installed.
fix
Use
from awsipranges import AWSIPPrefixes. error requests.exceptions.ConnectionError: HTTPSConnectionPool(host='ip-ranges.amazonaws.com', port=443): Max retries exceeded ↓
cause No internet access or the AWS IP ranges endpoint is unreachable (e.g., due to firewall or network issues).
fix
Ensure the machine has internet access and can reach https://ip-ranges.amazonaws.com/. Alternatively, use a proxy with the
proxies parameter. error AttributeError: 'list' object has no attribute 'filter' ↓
cause Calling `filter()` on the result of a previous `filter()` call, but `filter()` returns a list.
fix
Do not chain filters. Instead, save the first result and apply a second filter manually:
result = prefixes.filter(...); second = [p for p in result if ...]. Warnings
gotcha The filter() method returns a list of IP prefixes, not an AWSIPPrefixes object. Do not attempt to chain further filter calls. ↓
fix Store the result in a variable and iterate over it directly.
deprecated The `sync()` method is deprecated. Use `download()` instead. ↓
fix Replace `prefixes.sync()` with `prefixes.download()`.
gotcha The library requires Python >=3.7,<4.0. Using Python 3.6 or 4.0+ will cause install failures. ↓
fix Ensure your Python version is in the supported range (3.7-3.11 tested).
Imports
- AWSIPPrefixes
from awsipranges import AWSIPPrefixes
Quickstart
from awsipranges import AWSIPPrefixes
# Download current AWS IP ranges
prefixes = AWSIPPrefixes()
prefixes.download()
# Filter for us-east-1 region, EC2 service
ec2_us_east1 = prefixes.filter(regions=['us-east-1'], services=['EC2'])
print(f"Found {len(ec2_us_east1)} prefixes for EC2 in us-east-1")
# Access the MD5 hash (available since 0.3.0)
print(f"MD5 hash: {prefixes.md5}")