Last active
August 29, 2015 14:06
-
-
Save masaomoc/842053a2311d0b83c37d to your computer and use it in GitHub Desktop.
get RDS ARN for tags API
This file contains 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
require 'aws-sdk' | |
# return 12 digits account number | |
# if failed, raise RuntimeError | |
def get_account_id | |
iam = AWS::IAM::Client.new | |
begin | |
iam.get_user.user.arn =~ /arn:aws:iam::(\d{12}):user\/.*/ | |
rescue => e | |
e.message =~ /arn:aws:iam::(\d{12}):user\/.*/ | |
end | |
raise RuntimeError if $1.nil? | |
$1 | |
end | |
# return Array of RDS ARN | |
def get_rds_arn | |
rds = AWS::RDS.new | |
account_id = get_account_id | |
rds.instances.map{ |i| "arn:aws:rds:#{AWS.config.region}:#{account_id}:db:#{i.db_instance_identifier}" } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment