chriskacerguis
11/25/2014 - 7:05 PM

Create VM in AWS via Ruby AWS SDK

Create VM in AWS via Ruby AWS SDK

require 'aws-sdk'
require 'net/http'

ec2 = AWS::EC2.new(
:access_key_id => 'YOUR_ACCESS_KEY_ID',
:secret_access_key => 'YOUR_SECRET_ACCESS_KEY')

# Create our VM
instance = ec2.instances.create(
  :image_id => 'ami-9eaa1cf6',
  :instance_type => 'm3.medium',
  :security_groups => 'my-team',
  :key_pair => ec2.key_pairs['YOUR_SSH_KEY_NAME'])

# Wait until the instance is running
sleep 10 while instance.status == :pending
instance.tag('Name', :value => 'VM name')