Skip to content

Commit 8bcb005

Browse files
authored
Filter out Organizational accounts not in the ACTIVE state (#981)
When selecting Organization accounts to be included in the SEA Uninstall process, those in the SUSPENDED or PENDING_CLOSURE state are included. This leads to a failure whereby the SEA IAM role cannot be assumed for these accounts. This change filters all accounts not in the ACTIVE state.
1 parent 67740ae commit 8bcb005

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

reference-artifacts/Custom-Scripts/SEA-uninstall/aws-sea-cleanup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ def get_accounts():
4545
paginator = organizations.get_paginator('list_accounts')
4646
page_iterator = paginator.paginate()
4747
for aws_accounts in page_iterator:
48-
tmp = map(lambda x: [x["Id"], x["Name"]], aws_accounts["Accounts"])
48+
active_accounts = list(filter(lambda x: (x['Status'] == "ACTIVE"), aws_accounts["Accounts"]))
49+
tmp = map(lambda x: [x["Id"], x["Name"]], active_accounts)
4950

5051
print(tabulate(list(tmp), headers=["Id", "Name"]))
5152

0 commit comments

Comments
 (0)