Created
February 10, 2019 23:50
-
-
Save kirs/f849147f3e247f142a920c17d2823dd5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem "aws-sdk", "~> 3.0" | |
end | |
require 'aws-sdk' | |
ec2 = Aws::EC2::Resource.new(region: 'us-east-1') | |
nodes_request = 5 | |
node_type = 't3.2xlarge' # m5.12xlarge | |
puts "Requesting #{nodes_request} nodes of type #{node_type}" | |
instances = ec2.create_instances({ | |
image_id: 'ami-035be7bafff33b6b6', # Amazon Linux 2 AMI (HVM), SSD | |
min_count: nodes_request, | |
max_count: nodes_request, | |
key_name: 'kirs', | |
instance_type: node_type, | |
subnet_id: 'subnet-677f2f02', | |
}) | |
started_at = Time.now | |
instances.each do |instance| | |
puts "Waiting for #{instance.id}..." | |
# Wait for the instance to be created, running, and passed status checks | |
ec2.client.wait_until(:instance_status_ok, {instance_ids: [instance.id]}) | |
end | |
puts "Delta: #{(Time.now-started_at).round(2)}s" | |
# cleanup | |
instances.each do |instance| | |
instance.terminate | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment