Skip to content

Instantly share code, notes, and snippets.

@mndoci
Created December 19, 2010 23:57
Show Gist options
  • Select an option

  • Save mndoci/747850 to your computer and use it in GitHub Desktop.

Select an option

Save mndoci/747850 to your computer and use it in GitHub Desktop.
Simple script uses fog to provision an EC2 instance
#!/usr/bin/ruby
require 'rubygems'
require 'fog'
# Credentials in ./config.rb
require "./config.rb"
# Set up a connection
connection = Fog::Compute.new(:provider => 'AWS', :aws_access_key_id => @aws_access_key_id,
:aws_secret_access_key => @aws_secret_access_key)
server = connection.servers.create(:image_id => @ami_id,
:flavor_id => @default_instance_type,
:key_name => @key_name,
:availability_zone => @availability_zone)
# wait for it to be ready to do stuff
server.wait_for { print "."; ready? }
puts "Public IP Address: #{server.public_ip_address}"
puts "Private IP Address: #{server.private_ip_address}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment