Created
November 30, 2013 04:32
-
-
Save s-tajima/7715421 to your computer and use it in GitHub Desktop.
Check DNS Failover, and exec promote read replica.
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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'aws-sdk' | |
require 'resolv' | |
require 'pp' | |
$target_fqdn = 'target-fqen.example.com' | |
$target_elb = 'target-elb-XXXXXX.ap-northeast-1.elb.amazonaws.com' | |
$access_key_id = 'YOUR ACCESS KEY ID' | |
$secret_access_key = 'YOUR SECRET ACCESS KEY' | |
$failover_region = 'ap-southeast-1' | |
$failover_replica = 'drtest-apse' | |
fqdn_ip = Resolv.getaddress($target_fqdn) | |
elb_ip = Resolv.getaddress($target_elb) | |
if fqdn_ip == elb_ip | |
puts "[#{Time.now.strftime("%Y/%m/%d %H:%M:%S")}] Status OK." | |
exit | |
end | |
rds = AWS::RDS.new( | |
:access_key_id => $access_key_id, | |
:secret_access_key => $secret_access_key, | |
:region => $failover_region | |
).client | |
rds.promote_read_replica({:db_instance_identifier => $failover_replica}) | |
warn 'Failover occurd.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment