class Aws::Rds

API Reference: docs.amazonwebservices.com/AmazonRDS/latest/APIReference/

Constants

API_VERSION

Amazon API version being used

DEFAULT_HOST
DEFAULT_PATH
DEFAULT_PORT
DEFAULT_PROTOCOL

Public Class Methods

api() click to toggle source
# File lib/rds/rds.rb, line 23
def self.api
  @@api
end
bench() click to toggle source
# File lib/rds/rds.rb, line 30
def self.bench
  @@bench
end
bench_ec2() click to toggle source
# File lib/rds/rds.rb, line 39
def self.bench_ec2
  @@bench.service
end
bench_xml() click to toggle source
# File lib/rds/rds.rb, line 34
def self.bench_xml
  @@bench.xml
end
connection_name() click to toggle source
# File lib/rds/rds.rb, line 19
def self.connection_name
  :rds_connection
end
new(aws_access_key_id=nil, aws_secret_access_key=nil, params={}) click to toggle source
# File lib/rds/rds.rb, line 44
def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
  uri = ENV['RDS_URL'] ? URI.parse(ENV['RDS_URL']) : nil
  init({:name             => 'RDS',
        :default_host     => uri ? uri.host : DEFAULT_HOST,
        :default_port     => uri ? uri.port : DEFAULT_PORT,
        :default_service  => uri ? uri.path : DEFAULT_PATH,
        :default_protocol => uri ? uri.scheme : DEFAULT_PROTOCOL,
        :api_version      => API_VERSION},
       aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'],
       aws_secret_access_key|| ENV['AWS_SECRET_ACCESS_KEY'],
       params)
end

Public Instance Methods

authorize_db_security_group_ingress_ec2group(group_name, ec2_group_name, ec2_group_owner_id, options={}) click to toggle source
# File lib/rds/rds.rb, line 189
def authorize_db_security_group_ingress_ec2group(group_name, ec2_group_name, ec2_group_owner_id, options={})
  params                            = {}
  params['DBSecurityGroupName']     = group_name
  params['EC2SecurityGroupOwnerId'] = ec2_group_owner_id
  params['EC2SecurityGroupName']    = ec2_group_name
  link                              = do_request("AuthorizeDBSecurityGroupIngress", params)
rescue Exception
  on_exception
end
authorize_db_security_group_ingress_range(group_name, ip_range, options={}) click to toggle source
# File lib/rds/rds.rb, line 200
def authorize_db_security_group_ingress_range(group_name, ip_range, options={})
  params                        = {}
  params['DBSecurityGroupName'] = group_name
  params['CIDRIP']              = ip_range
  link                          = do_request("AuthorizeDBSecurityGroupIngress", params)
rescue Exception
  on_exception
end
create_db_instance(identifier, instance_class, allocated_storage, master_username, master_password, options={}) click to toggle source

identifier: db instance identifier. Must be unique per account per zone. instance_class: db.m1.small | db.m1.large | db.m1.xlarge | db.m2.2xlarge | db.m2.4xlarge See this for other values: docs.amazonwebservices.com/AmazonRDS/latest/APIReference/

options:

db_name: if you want a database created at the same time as the instance, specify :db_name option.
availability_zone: default is random zone.
# File lib/rds/rds.rb, line 89
def create_db_instance(identifier, instance_class, allocated_storage, master_username, master_password, options={})
  params                         = {}
  params['DBInstanceIdentifier'] = identifier
  params['DBInstanceClass']      = instance_class
  params['AllocatedStorage']     = allocated_storage
  params['MasterUsername']       = master_username
  params['MasterUserPassword']   = master_password

  params['Engine']               = options[:engine] || "MySQL5.1"
  params['DBName'] = options[:db_name] if options[:db_name]
  params['AvailabilityZone'] = options[:availability_zone] if options[:availability_zone]
  params['PreferredMaintenanceWindow'] = options[:preferred_maintenance_window] if options[:preferred_maintenance_window]
  params['BackupRetentionPeriod'] = options[:preferred_retention_period] if options[:preferred_retention_period]
  params['PreferredBackupWindow'] = options[:preferred_backup_window] if options[:preferred_backup_window]

  @logger.info("Creating DB Instance called #{identifier}")

  link = do_request("CreateDBInstance", params, :pull_out_single=>[:create_db_instance_result, :db_instance])

rescue Exception
  on_exception
end
create_db_security_group(group_name, description, options={}) click to toggle source
# File lib/rds/rds.rb, line 153
def create_db_security_group(group_name, description, options={})
  params                               = {}
  params['DBSecurityGroupName']        = group_name
  params['DBSecurityGroupDescription'] = description

  link                                 = do_request("CreateDBSecurityGroup", params, :pull_out_single => [:create_db_security_group_result, :db_security_group])

rescue Exception
  on_exception
end
delete_db_instance(identifier, final_snapshot_identifier=nil) click to toggle source

identifier: identifier of db instance to delete. final_snapshot_identifier: if specified, RDS will crate a final snapshot before deleting so you can restore it later.

# File lib/rds/rds.rb, line 135
def delete_db_instance(identifier, final_snapshot_identifier=nil)
  @logger.info("Deleting DB Instance - " + identifier.to_s)

  params                         = {}
  params['DBInstanceIdentifier'] = identifier
  if final_snapshot_identifier
    params['FinalDBSnapshotIdentifier'] = final_snapshot_identifier
  else
    params['SkipFinalSnapshot'] = true
  end

  link = do_request("DeleteDBInstance", params, :pull_out_single=>[:delete_db_instance_result, :db_instance])

rescue Exception
  on_exception
end
delete_db_security_group(group_name, options={}) click to toggle source
# File lib/rds/rds.rb, line 165
def delete_db_security_group(group_name, options={})
  params                        = {}
  params['DBSecurityGroupName'] = group_name

  link                          = do_request("DeleteDBSecurityGroup", params)

rescue Exception
  on_exception
end
describe_db_instances(options={}) click to toggle source

options:

DBInstanceIdentifier
MaxRecords
Marker

Returns array of instances as hashes. Response metadata can be retreived by calling array.response_metadata on the returned array.

# File lib/rds/rds.rb, line 120
def describe_db_instances(options={})
  params = {}
  params['DBInstanceIdentifier'] = options[:db_instance_identifier] if options[:db_instance_identifier]
  params['MaxRecords'] = options[:max_records] if options[:max_records]
  params['Marker'] = options[:marker] if options[:marker]

  resp = do_request("DescribeDBInstances", params, :pull_out_array=>[:describe_db_instances_result, :db_instances])

rescue Exception
  on_exception
end
describe_db_security_groups(options={}) click to toggle source
# File lib/rds/rds.rb, line 176
def describe_db_security_groups(options={})
  params = {}
  params['DBSecurityGroupName'] = options[:DBSecurityGroupName] if options[:DBSecurityGroupName]
  params['MaxRecords'] = options[:MaxRecords] if options[:MaxRecords]

  link = do_request("DescribeDBSecurityGroups", params, :pull_out_array=>[:describe_db_security_groups_result, :db_security_groups], :wrapper=>:db_security_group)


rescue Exception
  on_exception
end
do_request(action, params, options={}) click to toggle source
# File lib/rds/rds.rb, line 58
def do_request(action, params, options={})
  link = generate_request(action, params)
  resp = request_info_xml_simple(self.class.connection_name, @params, link, @logger,
                                 :group_tags     =>{"DBInstances"      =>"DBInstance",
                                                    "DBParameterGroups"=>"DBParameterGroup",
                                                    "DBSecurityGroups" =>"DBSecurityGroup",
                                                    "EC2SecurityGroups"=>"EC2SecurityGroup",
                                                    "IPRanges"         =>"IPRange"},
                                 :force_array    =>["DBInstances",
                                                    "DBParameterGroups",
                                                    "DBSecurityGroups",
                                                    "EC2SecurityGroups",
                                                    "IPRanges"],
                                 :pull_out_array =>options[:pull_out_array],
                                 :pull_out_single=>options[:pull_out_single],
                                 :wrapper        =>options[:wrapper])
end
revoke_db_security_group_ingress(group_name, ip_range, options={}) click to toggle source
# File lib/rds/rds.rb, line 210
def revoke_db_security_group_ingress(group_name, ip_range, options={})
  params                        = {}
  params['DBSecurityGroupName'] = group_name
  params['CIDRIP']              = ip_range
  link                          = do_request("RevokeDBSecurityGroupIngress", params)
rescue Exception
  on_exception
end