Skip to content

Instantly share code, notes, and snippets.

@ramhoj
Created July 4, 2016 12:49
Show Gist options
  • Save ramhoj/0edce86997d67da7fe50dc974b34f976 to your computer and use it in GitHub Desktop.
Save ramhoj/0edce86997d67da7fe50dc974b34f976 to your computer and use it in GitHub Desktop.
require "aws-sdk"
require "pry"
filename = File.expand_path("./deploy/video.rb", File.dirname(__FILE__))
config_file = File.open(filename, "w")
client = Aws::EC2::Client.new(
region: "eu-west-1",
access_key_id: "access_key_id",
secret_access_key: "secret_access_key"
)
all_instances = client.describe_instances.reservations.map(&:instances).flatten
running_instances = all_instances.select { |instance| instance.state.name == "running" }
running_video_instances = running_instances.select do |instance|
instance.tags.any? do |tag|
tag.key == "aws:autoscaling:groupName" && tag.value == "my-autoscaling-member"
end
end
running_video_instances.each do |instance|
config_file.puts %(server "#{instance.public_dns_name}", user: "ubuntu", roles: [:app], internal_ip: "#{instance.private_ip_address}")
end
config_file.close
puts File.read(filename)
puts "inspect #{filename} and run `cap prod deploy`."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment