python-3.xalibaba-cloud

How can I get the account ID number programmatically with Aliyun Python SDK?


I need to programmatically get the account ID number, in a way that does not depend on a local config file with info about local account configuration. I want to automate reports and need the ID number as a data point.


Solution

  • I am not aware of such an API to return only the account ID. But some APIs do return the account ID along with other information, e.g. this GetRole API. The account ID is part of the <Arn>acs:ram::123456789012****:role/ECSAdmin</Arn> so you can parse out the account ID.