Created
March 9, 2016 04:15
-
-
Save bmhatfield/4c9eed784a03d495b6e2 to your computer and use it in GitHub Desktop.
Output a human-readable & colorized view of your EC2 security group rules
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
#!/usr/bin/env ruby | |
require 'aws-sdk' | |
require 'colorize' | |
ec2 = Aws::EC2::Resource.new | |
ec2.security_groups.sort_by{|s| s.group_name }.each do |sg| | |
puts sg.group_name.underline unless sg.ip_permissions.empty? | |
sg.ip_permissions.each do |perm| | |
ip_ranges = perm.ip_ranges.map{ |r| r.cidr_ip == '0.0.0.0/0' ? r.cidr_ip.red : r.cidr_ip }.join(", ") | |
groups = perm.user_id_group_pairs.map{ |r| r.group_name}.join(", ") | |
puts " #{perm.ip_protocol}/#{perm.from_port} -> instance:#{perm.to_port}".yellow | |
puts " #{groups}" unless groups.empty? | |
puts " #{ip_ranges}" unless ip_ranges.empty? | |
puts | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An example: