How to find IP ranges used by AWS S3

This post explains how to get current IP address ranges used by AWS services using Python. AWS publishes its IP ranges in .json file that can be downloaded from here.

Import required modules
   
import json
import requests
 
Get json file content using requests.get
   
aws_ip_ranges_url = "https://ip-ranges.amazonaws.com/ip-ranges.json"

aws_ip_ranges = json.loads(requests.get(aws_ip_ranges_url).text)
 
Get AWS IP ranges used by AWS S3
   
for ip_range in aws_ip_ranges["prefixes"]:
    if ip_range["service"] == "S3":
        print(ip_range["service"], ip_range["ip_prefix"], ip_range["region"])
 
Get AWS IP ranges used by AWS CLOUDFRONT
   
for ip_range in aws_ip_ranges["prefixes"]:
    if ip_range["service"] == "CLOUDFRONT":
        print(ip_range["service"], ip_range["ip_prefix"], ip_range["region"])
 
Get AWS IP ranges used by AWS ROUTE53_HEALTHCHECKS
   
for ip_range in aws_ip_ranges["prefixes"]:
    if ip_range["service"] == "ROUTE53_HEALTHCHECKS":
        print(ip_range["service"], ip_range["ip_prefix"], ip_range["region"])

 
Get AWS IP ranges used by AMAZON_APPFLOW
   
for ip_range in aws_ip_ranges["prefixes"]:
    if ip_range["service"] == "AMAZON_APPFLOW":
        print(ip_range["service"], ip_range["ip_prefix"], ip_range["region"])

 
Get AWS IP ranges used by KINESIS_VIDEO_STREAMS
   
for ip_range in aws_ip_ranges["prefixes"]:
    if ip_range["service"] == "KINESIS_VIDEO_STREAMS":
        print(ip_range["service"], ip_range["ip_prefix"], ip_range["region"])

 
Complete snippet for getting IP ranged used by AWS services
   
import json
import requests

aws_ip_ranges_url = "https://ip-ranges.amazonaws.com/ip-ranges.json"

aws_ip_ranges = json.loads(requests.get(aws_ip_ranges_url).text)

for ip_range in aws_ip_ranges["prefixes"]:
    if ip_range["service"] == "S3":
        print(ip_range["service"], ip_range["ip_prefix"], ip_range["region"])


for ip_range in aws_ip_ranges["prefixes"]:
    if ip_range["service"] == "CLOUDFRONT":
        print(ip_range["service"], ip_range["ip_prefix"], ip_range["region"])


for ip_range in aws_ip_ranges["prefixes"]:
    if ip_range["service"] == "ROUTE53_HEALTHCHECKS":
        print(ip_range["service"], ip_range["ip_prefix"], ip_range["region"])

for ip_range in aws_ip_ranges["prefixes"]:
    if ip_range["service"] == "AMAZON_APPFLOW":
        print(ip_range["service"], ip_range["ip_prefix"], ip_range["region"])

for ip_range in aws_ip_ranges["prefixes"]:
    if ip_range["service"] == "KINESIS_VIDEO_STREAMS":
        print(ip_range["service"], ip_range["ip_prefix"], ip_range["region"])
 

Category: AWS