Skip to content

Instantly share code, notes, and snippets.

@mmasashi
Created March 13, 2013 00:10
Show Gist options
  • Save mmasashi/5148298 to your computer and use it in GitHub Desktop.
Save mmasashi/5148298 to your computer and use it in GitHub Desktop.
Launch an Amazon Redshift Cluster with aws-sdk for ruby. Ref -> http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/Redshift/Client.html
require 'aws-sdk'
ACCESS_KEY_ID=ENV['AWS_KEY_ID']
SECRET_ACCESS_KEY=ENV['AWS_SEC_KEY']
CLUSTER_IDENTIFIER='test-instance'
DB_NAME='testdb'
PORT_NUMBER=5439
MASTER_USERNAME='test_admin'
MASTER_USER_PASSWORD=ENV['MASTER_USER_PASSWORD']
# minimum(single node) cluster options
CLUSTER_OPTION={
:db_name => DB_NAME,
:cluster_identifier => CLUSTER_IDENTIFIER,
:cluster_type => 'single-node',
:node_type => 'dw.hs1.xlarge',
:master_username => MASTER_USERNAME,
:master_user_password => MASTER_USER_PASSWORD
}
# initialize
@redshift = AWS::Redshift.new(
:access_key_id => ACCESS_KEY_ID,
:secret_access_key => SECRET_ACCESS_KEY)
# check the number of clusters
response = @redshift.client.describe_clusters
response and response.clusters and response.clusters.each do |c|
if c.cluster_identifier == CLUSTER_IDENTIFIER
puts "Already #{CLUSTER_IDENTIFIER} exists."
exit 1
end
end
# create cluster
response = @redshift.client.create_cluster(CLUSTER_OPTION)
if response
puts "Succeeded to launch a cluster. instance:#{CLUSTER_IDENTIFIER}"
exit 0
else
puts "Failed to launch a cluster. instance:#{CLUSTER_IDENTIFIER}"
exit 2
end
@miketaluc-bytecode
Copy link

thanks for the late night coding scramble gift. hopefully some of the redshift administration answers i've been posting in stackoverflow will pay you back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment