Sometimes it’s handy to know what IP address ranges are used in different AWS Regions. You may want to whitelist access to your region AWS endpoints, or from global CloudFront location, or set up some special routing rules, or look up which region a certain IP belongs to.
ip-ranges.json & filter-ip-ranges
If you just run it it will print all the ranges from all regions and services.
~/aws-utils $ ./filter-ip-ranges # SERIAL=1545170057 22.214.171.124/15 126.96.36.199/14 188.8.131.52/14 [... 860 more ...] 184.108.40.206/22 220.127.116.11/23 18.104.22.168/23
It’s a good start, the script apparently works and can download and parse the ip-ranges.json file.
How about printing only the prefixes from Sydney region (
ap-southeast-2) with some extra info (
~/aws-utils $ filter-ip-ranges -v ap-southeast-2 # SERIAL=1545170057 # 1323 prefixes found / 865 prefixes consolidated / 38 prefixes matching 22.214.171.124/14 ap-southeast-2 AMAZON EC2 126.96.36.199/26 ap-southeast-2 CLOUDFRONT 188.8.131.52/29 ap-southeast-2 CODEBUILD 184.108.40.206/26 ap-southeast-2 AMAZON_CONNECT 220.127.116.11/22 ap-southeast-2 AMAZON S3 [...] 18.104.22.168/16 ap-southeast-2 AMAZON EC2 22.214.171.124/26 ap-southeast-2 ROUTE53_HEALTHCHECKS 126.96.36.199/26 ap-southeast-2 ROUTE53_HEALTHCHECKS 188.8.131.52/16 ap-southeast-2 AMAZON EC2 184.108.40.206/22 ap-southeast-2 AMAZON
As we can see each prefix has some tags – is it used for EC2? S3? CloudFront? Route53 Health Checks?
Let’s see what prefixes are used for S3 in the Sydney region:
~/aws-utils $ ./filter-ip-ranges -v ap-southeast-2 S3 220.127.116.11/22 ap-southeast-2 AMAZON S3 18.104.22.168/21 ap-southeast-2 AMAZON S3 22.214.171.124/22 ap-southeast-2 AMAZON S3 126.96.36.199/24 ap-southeast-2 AMAZON S3
Or maybe you’re after all Cloud Front prefixes all around the world to create a whitelist for your firewall?
~/aws-utils $ ./filter-ip-ranges -v CLOUDFRONT 188.8.131.52/15 GLOBAL AMAZON CLOUDFRONT 184.108.40.206/16 GLOBAL AMAZON CLOUDFRONT 220.127.116.11/26 ap-southeast-2 CLOUDFRONT 18.104.22.168/26 us-east-2 CLOUDFRONT 22.214.171.124/24 ap-northeast-1 CLOUDFRONT [...]
The GLOBAL ones are edge-locations, the ones with region name are, well, in that region.
Looking up IP addresses
Finally we can check to which region belongs a given IP address, let’s say this blog’s address:
~/aws-utils $ ./filter-ip-ranges -v 126.96.36.199 # SERIAL=1545170057 # 1323 prefixes found / 865 prefixes consolidated / 1 prefixes matching 188.8.131.52/15 ap-southeast-2 AMAZON EC2
Not surprisingly it’s in the Sydney region as we can see from the
One little issue we see here is that in
ip-ranges.json quite a lot is hidden under the EC2 label – even though this blog’s IP is actually an Elastic Load Balancer the prefix tag is EC2 and not ELB. We can’t do much about it until Amazon labels the prefixes in the JSON file in a more granular way.
I hope you find this little script handy!