2

Is there anyway to get UserId or a.k.a. AWS Account ID?

I have checked the documentation but could not locate (...or probably it doesn't exists...) a method call which returns the UserId.

TeaCupApp
  • 11,316
  • 18
  • 70
  • 150
  • You mean you want to get the `iam`, right? `[Here's the proper documentation](http://docs.aws.amazon.com/IAM/latest/APIReference/API_GetUser.html) – Ohgodwhy Jan 15 '14 at 00:31
  • Not really, I am looking for account id. It is located on right hand side when you open AWS Console > My Account – TeaCupApp Jan 15 '14 at 00:45

3 Answers3

4

Sort of. There's no way to get it without creating a resource. Many resources have an ARN associated with it. You can extract the Account ID from the ARN, but you'd have to create a resource first.

Ryan Parman
  • 6,855
  • 1
  • 29
  • 43
  • Thanks Ryan, Would expect this to be a Common method call as there are plenty of function which requires Account-Id to be passed. Specially modifyImageAttribute :). Creating resources seems to be overkill :) – TeaCupApp Jan 15 '14 at 05:54
4

I haven't used the PHP SDK, but AWS have added a GetCallerIdentity API call in STS which can give you both the User ID and the Account ID. It's available here:

https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-sts-2011-06-15.html#getcalleridentity

$result = $client->getCallerIdentity([/* ... */]);

Returns:

[
  'Account' => '<string>',
  'Arn' => '<string>',
  'UserId' => '<string>',
]
Steve N
  • 1,371
  • 1
  • 12
  • 18
1

You CAN, actually, extract account-id from User's ARN. Without creating any "additional" resources, as IAM User is already an Resource.

GetUser call on IAM Client. Then parse the ARN string by pattern.

Paul Rysevets
  • 39
  • 1
  • 4