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 126.96.36.199/15 188.8.131.52/14 184.108.40.206/14 [... 860 more ...] 220.127.116.11/22 18.104.22.168/23 22.214.171.124/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 126.96.36.199/14 ap-southeast-2 AMAZON EC2 188.8.131.52/26 ap-southeast-2 CLOUDFRONT 184.108.40.206/29 ap-southeast-2 CODEBUILD 220.127.116.11/26 ap-southeast-2 AMAZON_CONNECT 18.104.22.168/22 ap-southeast-2 AMAZON S3 [...] 22.214.171.124/16 ap-southeast-2 AMAZON EC2 126.96.36.199/26 ap-southeast-2 ROUTE53_HEALTHCHECKS 188.8.131.52/26 ap-southeast-2 ROUTE53_HEALTHCHECKS 184.108.40.206/16 ap-southeast-2 AMAZON EC2 220.127.116.11/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 18.104.22.168/22 ap-southeast-2 AMAZON S3 22.214.171.124/21 ap-southeast-2 AMAZON S3 126.96.36.199/22 ap-southeast-2 AMAZON S3 188.8.131.52/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 184.108.40.206/15 GLOBAL AMAZON CLOUDFRONT 220.127.116.11/16 GLOBAL AMAZON CLOUDFRONT 18.104.22.168/26 ap-southeast-2 CLOUDFRONT 22.214.171.124/26 us-east-2 CLOUDFRONT 126.96.36.199/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 188.8.131.52 # SERIAL=1545170057 # 1323 prefixes found / 865 prefixes consolidated / 1 prefixes matching 184.108.40.206/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!