Reputation: 32335
As can be seen in this question, the Java SDK has a method to retrieve the current user based on the request's credentials. Is there a way to do something similar using the Ruby SDK?
I've tried AWS::IAM.new(creds).access_keys[creds[:access_key_id]]
, but that returns a simple object that answers nil
to user
or user_name
, and my user doesn't have the iam:ListUsers
permission so I can't enumerate the users collection.
Basically I need that information because I want to generate a self-approving policy to be attached to some new resources, and I need to fetch the ARN that my configured access key is associated with. Any suggestions?
Upvotes: 2
Views: 1111
Reputation: 6528
You can get the current user using the client class. If you are using version 1 of the AWS SDK for Ruby, the aws-sdk
gem:
iam = AWS::IAM::Client.new
iam.get_user
If you prefer to use the new version 2 AWS SDK for Ruby, just change the root namespace from AWS
to Aws
:
iam = Aws::IAM::Client.new
iam.get_user
Upvotes: 2