Created
June 14, 2021 06:45
-
-
Save miyataka/2b4bcecc77984df61c6dbae43cffe7df to your computer and use it in GitHub Desktop.
one liner: generate prefix list array from aws ip range json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://docs.aws.amazon.com/ja_jp/general/latest/gr/aws-ip-ranges.html#aws-ip-egress-control | |
# requirements | |
# - curl | |
# - jq | |
require 'json' | |
require 'yaml' | |
REGION='ap-northeast-1' | |
iprange_strings = `curl https://ip-ranges.amazonaws.com/ip-ranges.json | jq -r '[.prefixes[] | select(.service=="AMAZON" and .region=="#{REGION}").ip_prefix] - [.prefixes[] | select(.service=="EC2").ip_prefix] | .[]'` | |
ipranges = iprange_strings.split("\n") | |
result = ipranges.map do |cidr| | |
puts cidr | |
{ "Cidr" => cidr } | |
end | |
puts "json version" | |
puts result.to_json | |
puts "yaml version" | |
puts result.to_yaml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment