Reputation: 3895
Using fog library of ruby how can I get the account ID of the current authentication? I use access_key_id
and secret_access_key
to authenticate.
Upvotes: 3
Views: 1376
Reputation: 10237
You can get this info through get-caller-identity
API of STS service.
In Ruby:
Aws::STS::Client.new(your_oprions).get_caller_identity[:account]
Upvotes: 2
Reputation: 3498
There's no such call to get raw accounID in all the api. However theres a nice trick to do it thru get_user
call from IAM API
If you are calling AWS API you are necesarily using an IAM user keys to do so. Every IAM user has an ARN (amazon resource name) that ARN should contain the AccountID on it.
I don't know how using fog but using AWS-SDK you can use Aws::IAM::CurrentUser
require 'aws-sdk'
i = Aws::IAM::CurrentUser.new(region: region, credentials: credentials)
puts i.arn
You should see the ARN of the caller user, with the AccountID on it. Also thru aws-cli console application you'll get the same answer using
aws iam get-user --query "User.Arn"
Perhaps there's something similar in Fog
Upvotes: 2