amazon ip ranges in varnish
I just recently realized that amazon exposes all of their ip ranges in a easy to get json format here (https://ip-ranges.amazonaws.com/ip-ranges.json)
you can also read the docs here (http://docs.aws.amazon.com/general/latest/gr/aws-ip-ranges.html)
So I made this python script to fetch the latest ip ranges from amazon and place them in a varnish vcl file in order for me to use it as an ACL in varnish.
#!/usr/bin/env python
from __future__ import print_function
import json
import requests
import re
amazon_url = "https://ip-ranges.amazonaws.com/ip-ranges.json"
r = requests.get(amazon_url)
json_response = r.json()
f = open('aws.vcl','w')
print("# Created date: " + json_response['createDate'], file=f)
print("acl aws {", file=f)
prefixes = json_response['prefixes']
for prefix in prefixes:
varniship = re.sub(r'^',' "', prefix['ip_prefix'])
varniship = re.sub(r'(\/\d+)$', '"\\1;', varniship )
varniship += "\t\t# Service: " + prefix['service'] + " Region: " + prefix['region']
print(varniship, file=f)
print("}", file=f)
f.close