Reputation: 97
I am using a API call to retrieve the plaintext instance identity document. Here, accountId is present.
response = response.get("http://169.254.169.254/latest/dynamic/instance-identity/document").text
I am using the above code in my python script. How can i get AWS userId by API call?
Upvotes: -1
Views: 2706
Reputation: 238957
Not sure if this is what you are after, but get_caller_identity returns UserId
and Accountid
:
UserId (string) The unique identifier of the calling entity. The exact value depends on the type of entity that is making the call. The values returned are those listed in the aws:userid column in the Principal table found on the Policy Variables reference page in the IAM User Guide .
Account (string) The AWS account ID number of the account that owns or contains the calling entity.
Arn (string) The AWS ARN associated with the calling entity.
Example output is (from docs):
'Account': '123456789012',
'Arn': 'arn:aws:iam::123456789012:user/Alice',
'UserId': 'AKIAI44QH8DHBEXAMPLE'
Upvotes: 2