To simply shell out to curl and jq to get that data,
import subprocess
data = subprocess.check_output("""curl https://ip-ranges.amazonaws.com/ip-ranges.json | jq -r '.prefixes[] | select(.region=="ap-southeast-1") | .ip_prefix'""", shell=True)
but you really probably shouldn't do that since e.g. there's no guarantee you have curl
and jq
in the Lambda execution environment (not to mention the overhead).
Instead, if you have the requests
library,
import requests
resp = requests.get("https://ip-ranges.amazonaws.com/ip-ranges.json")
resp.raise_for_status()
prefixes = {
r["ip_prefix"]
for r in resp.json()["prefixes"]
if r["region"] == "ap-southeast-1"
}