AWS Organizations - list accounts for role [boto3]

0

Hi,

We are planning to support for AWS Organizations in our product. We will need to retrieve very often the list of AWS accounts belonging to a given organization. Instead of frequently traversing the organization tree to discover new/deleted accounts (it may be slow), I wonder if there is any boto3 binding or api endpoint to list all organization accounts (and ideally filter by role). Thanks in advance.

Regards

Roberto
asked 4 months ago189 views
1 Answer
1
Accepted Answer

Hello.

You can get a list of accounts in Organizations by using list_accounts() described in the following document.
However, this cannot display a list of accounts across organizations, so if you want to cross organizations, you will need to set up cross-account roles, etc.
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/organizations/client/list_accounts.html

I think list_children() can be used to list by OU.
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/organizations/client/list_children.html

profile picture
EXPERT
answered 4 months ago
profile pictureAWS
EXPERT
reviewed 4 months ago
  • Thank you @Riku - I wonder how the heck I went over this endpoint without noticing... Thanks!

    to list by OU I have found list_accounts_for_parent()

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions