-
Notifications
You must be signed in to change notification settings - Fork 7
/
rds.rb
63 lines (56 loc) · 2.06 KB
/
rds.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require './config'
def rds
@rds ||= Aws::RDS::Client.new(region: @region)
end
def create_db_instance
db_name = ''
allocated_storage = 5
db_instance_class = 'db.t2.micro'
@db_instance_identifier = 'rdslab'
@master_username = 'root'
@master_user_password = random_token
engine = 'mysql'
storage_type = 'gp2'
backup_retention_period = 0
resp = rds.create_db_instance \
engine: engine, db_instance_class: db_instance_class,
allocated_storage: allocated_storage, storage_type: storage_type,
db_instance_identifier: @db_instance_identifier,
backup_retention_period: backup_retention_period,
master_username: @master_username, master_user_password: @master_user_password
end
def create_db_instance_waiter
raise '@db_instance_identifier missing' unless @db_instance_identifier
resp = rds.wait_until \
:db_instance_available, db_instance_identifier: @db_instance_identifier
@endpoint_address = resp[:db_instances][0][:endpoint][:address]
@endpoint_port = resp[:db_instances][0][:endpoint][:port]
resp
end
def delete_db_instance
raise '@db_instance_identifier missing' unless @db_instance_identifier
resp = rds.delete_db_instance \
db_instance_identifier: @db_instance_identifier, skip_final_snapshot: true
end
def delete_db_instance_waiter
raise '@db_instance_identifier missing' unless @db_instance_identifier
resp = rds.wait_until \
:db_instance_deleted, db_instance_identifier: @db_instance_identifier
true
end
def cleanup
puts 'Deleting DB instance...'; ap resp = delete_db_instance
puts 'Waiting for deletion...'; ap resp = delete_db_instance_waiter
true
end
def run
puts "Region: #{@region}"
puts 'Creating database...'; ap resp = create_db_instance
puts 'Waiting for database...'; ap resp = create_db_instance_waiter
puts "Host: #{@endpoint_address}"
puts "Port: #{@endpoint_port}"
puts "Master Username: #{@master_username}"
puts "Master User Password: #{@master_user_password}"
puts "mysql command-line: mysql -h #{@endpoint_address} -u #{@master_username} -p#{@master_user_password}"
true
end