Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Output a human-readable & colorized view of your EC2 security group rules
#!/usr/bin/env ruby
require 'aws-sdk'
require 'colorize'
ec2 =
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 ={ |r| r.cidr_ip == '' ? : r.cidr_ip }.join(", ")
groups ={ |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?

This comment has been minimized.

Copy link
Owner Author

@bmhatfield bmhatfield commented Mar 9, 2016

An example:

screen shot 2016-03-08 at 11 19 14 pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.