Skip to content

Instantly share code, notes, and snippets.

@mechamogera
Created September 5, 2012 02:20
Show Gist options
  • Save mechamogera/3629296 to your computer and use it in GitHub Desktop.
Save mechamogera/3629296 to your computer and use it in GitHub Desktop.
EC2上で設定したroleのAccessKeyを取得するRubyスクリプト
require 'uri'
require 'json'
require 'net/http'
role = Net::HTTP.get(URI.parse("http://169.254.169.254/latest/meta-data/iam/security-credentials/"))
ret = Net::HTTP.get(URI.parse("http://169.254.169.254/latest/meta-data/iam/security-credentials/#{role}"))
dat = JSON.parse(ret)
puts dat["AccessKeyId"]
puts dat["SecretAccessKey"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment