Skip to content

Instantly share code, notes, and snippets.

@nightspotlight
Created December 17, 2025 15:56
Show Gist options
  • Select an option

  • Save nightspotlight/553913640f4c038dacd811e6291fd293 to your computer and use it in GitHub Desktop.

Select an option

Save nightspotlight/553913640f4c038dacd811e6291fd293 to your computer and use it in GitHub Desktop.
Sedai script to update group with AWS accounts
account_id account_name
012345678901 testacc1
123456789012 testacc2
#!/usr/bin/env python3
import csv
from sedai import account, groups, models
def main():
csvfile = 'aws_accounts.csv'
group_name = 'XYZ AWS Accounts'
group = groups.get_group(group_name)
if not group:
print(f"Group \"{group_name}\" not found, creating it.")
group_definition = groups.GroupDefinition(group_name)
create_status = groups.create_group(group_definition)
group = groups.get_group(group_name)
print(f"Group {group_name} ({group.groupId}) created with status {create_status}")
else:
group_definition = group.definition
print(f"Group \"{group_name}\" found with id {group.groupId}")
with open(csvfile, newline='') as f:
reader = csv.DictReader(f)
for row in reader:
# Look up Sedai internal account id by AWS account id
accounts = account.search_accounts_by_provider_account_id(row['account_id'])
account_id = models.to_dict(accounts)[0]['id']
group_definition.add_account_id(account_id)
print(f"Added account {row['account_id']} to group \"{group_name}\"")
groups.update_group(group)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment