Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@drnic
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drnic/9118928 to your computer and use it in GitHub Desktop.
Save drnic/9118928 to your computer and use it in GitHub Desktop.
AWS VPC fog snippets

Find a RouteTable for a given public Subnet:

subnet = Fog::Compute["aws"].subnets.last
subnet_id = subnet.subnet_id

rts = Fog::Compute["aws"].route_tables
route_table_for_subnet = rts.find {|rt| rt.associations.find {|assoc| assoc["subnetId"] == subnet_id} }

If route_table_for_subnet is nil then the subnet is private.

Or run the vpc_subnets.rb script:

$ ruby subnets.rb
subnet-825d74d4: private
subnet-835d74d5: public
require "fog"
credentials = {
provider: "AWS",
aws_access_key_id: "KEY",
aws_secret_access_key: "SECRET"
}
compute = Fog::Compute.new(credentials)
compute.subnets.each do |subnet|
print "#{subnet.subnet_id}: "
subnet_id = subnet.subnet_id
rts = compute.route_tables
route_table_for_subnet = rts.find {|rt| rt.associations.find {|assoc| assoc["subnetId"] == subnet_id} }
puts route_table_for_subnet ? "public" : "private"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment