Skip to content

Instantly share code, notes, and snippets.

@studio3104
Created November 30, 2012 09:16
Show Gist options
  • Save studio3104/4174693 to your computer and use it in GitHub Desktop.
Save studio3104/4174693 to your computer and use it in GitHub Desktop.
Fluentd Hands On
#!/usr/bin/env ruby
require 'aws-sdk'
require 'pp'
AWS.config(:proxy_uri => ENV['http_proxy'])
config_path = File.expand_path(File.dirname(__FILE__)+"/keys.yml")
AWS.config(YAML.load(File.read(config_path)))
ec2 = AWS::EC2.new
key_name = security_group_name = 'fluentd_hands_on'
allow_from = "YOUR COMPANY IP ADDRESS (0.0.0.0/0)"
# Created if key pair does not exist
if AWS::EC2::KeyPair.new(key_name).exists?
puts "key pair already exists, \"#{key_name}\""
else
kp = ec2.key_pairs.create(key_name)
private_key_file = open('./id_rsa', 'w+')
private_key_file.write(kp.private_key)
private_key_file.close
puts "created key pair, \"#{key_name}\""
end
private_key_file = open('./id_rsa', 'r')
p private_key_file.read
# Created if security group does not exist
if ec2.security_groups.filter('group-name', security_group_name).first
puts "security group already exists, \"#{security_group_name}\""
else
group = ec2.security_groups.create(security_group_name)
group.authorize_ingress(:tcp, 22, allow_from)
group.authorize_ingress(:tcp, 80, allow_from)
puts "created security group, \"#{security_group_name}\""
end
p ec2.instances.create(
# :count => 2,
:image_id => 'ami-c0bbf892',
:key_name => key_name,
:security_groups => security_group_name,
:instance_type => 't1.micro'
)
access_key_id: YOUR ACCESS KEY
secret_access_key: YOUR PASSWORD
ec2_endpoint : ec2.ap-southeast-1.amazonaws.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment