Skip to content

Commit ff55798

Browse files
authored
Merge pull request #7 from nbkem1/patch-1
Update README.md
2 parents 8b3f0e5 + 46a4f97 commit ff55798

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,31 @@ Example:
137137
```
138138
111122223333,srodriguez@example.com
139139
444455556666,rroe@example.com
140+
141+
```
142+
A CSV file can also be generated from the Organizations Master or an account that is Delegated Administrator for GuardDuty/IAM Access Analyzer by running the below code:
143+
140144
```
145+
import boto3
146+
import csv
147+
import os
148+
149+
## Exports Organizations members as CSV to be used as input for Amazon Detective
141150
151+
client = boto3.client('organizations')
152+
153+
def create_accounts_csv():
154+
paginator = client.get_paginator('list_accounts')
155+
page_iterator = paginator.paginate()
156+
with open('accounts.csv', mode='w', newline='') as accounts_file:
157+
writer = csv.writer(accounts_file, dialect='excel', delimiter='"', lineterminator='')
158+
for r in page_iterator:
159+
for key in r['Accounts']:
160+
writer.writerows(key['Id']+',')
161+
writer.writerows(key['Email']+'\n')
162+
163+
create_accounts_csv()
164+
```
142165

143166
## Executing the scripts
144167

0 commit comments

Comments
 (0)