Skip to content

Instantly share code, notes, and snippets.

@blindsey
Created October 19, 2012 03:57
Show Gist options
  • Save blindsey/3916140 to your computer and use it in GitHub Desktop.
Save blindsey/3916140 to your computer and use it in GitHub Desktop.
EC2 ssh config builder for aliases
#!/usr/bin/env ruby
require 'rubygems'
require 'aws'
File.open("#{ENV['HOME']}/.ssh/config", 'w') do |file|
@ec2 = Aws::Ec2.new(ENV['AWS_KEY'], ENV['AWS_SECRET'])
@ec2.describe_instances.each do |instance|
next unless instance[:aws_state] == 'running'
file.puts "Host #{instance[:tags]['Name'].sub(/(\d)\D+$/, '\1') }"
file.puts " Hostname #{instance[:dns_name]}"
file.puts " User ubuntu"
file.puts
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment