Programmatically obtaining the list of Amazon Quick groups and members of the groups

This article provides a python code which utilizes boto3 Application Programming Interfaces (API’s) to programmatically obtain the list of Amazon Quick groups and members of those groups.

Our customers often reach out to us seeking guidance in finding the members or users who are part of a Quick group. This is a difficult task to be performed in the console as it may require manual effort to open every group and then find the members. In order to make this task easier, I have developed a python code which provides the list of all Amazon Quick groups along with the user Amazon Resource Names (ARNs) of users who are a part of these groups.

Please see below:

import boto3

# Set your AWS region
region = 'us-east-1'

# Create a QuickSight client
quicksight_client = boto3.client(
    'quicksight',
    region_name=region
)

# Specify your AWS Account ID
account_id = 'XXXXXXXXXXXX'  # Replace with your actual AWS account ID


def list_all_groups(account_id):
    """List all QuickSight groups, handling pagination."""
    groups = []
    next_token = None

    while True:
        params = {
            'AwsAccountId': account_id,
            'Namespace': 'default'
        }
        if next_token:
            params['NextToken'] = next_token

        response = quicksight_client.list_groups(**params)
        groups.extend(response.get('GroupList', []))

        next_token = response.get('NextToken')
        if not next_token:
            break

    return groups


def list_all_group_members(account_id, group_name):
    """List all members of a QuickSight group, handling pagination."""
    members = []
    next_token = None

    while True:
        params = {
            'AwsAccountId': account_id,
            'GroupName': group_name,
            'Namespace': 'default'
        }
        if next_token:
            params['NextToken'] = next_token

        response = quicksight_client.list_group_memberships(**params)
        members.extend(response.get('GroupMemberList', []))

        next_token = response.get('NextToken')
        if not next_token:
            break

    return members


# List all QuickSight groups
groups = list_all_groups(account_id)

# Iterate through groups and list members
for group in groups:
    group_name = group['GroupName']
    group_arn = group['Arn']

    print(f"Group Name: {group_name}")
    print(f"Group Arn: {group_arn}")

    # Get all members for each group
    members = list_all_group_members(account_id, group_name)

    # Print members
    if members:
        print("Members:")
        for member in members:
            print(f"  User Name: - {member['MemberName']}")
            print(f"  User Arn: - {member['Arn']}")
    else:
        print("No members in this group")

    print("\n")

The output will provide all the Amazon Quick groups and users who are a part of those groups.

Sample Output:

Group Name: EmbeddedDemoReaders
Group Arn: arn:aws:quicksight:us-east-1:XXXXXXXXXXXX:group/default/EmbeddedDemoReaders
Members:
  User Name: - Admin
  User Arn: - arn:aws:quicksight:us-east-1:XXXXXXXXXXXX:user/default/Admin
  User Name: - QSER/DemoUser
  User Arn: - arn:aws:quicksight:us-east-1:XXXXXXXXXXXX:user/default/QSER/DemoUser

NOTE: AWS Support does not provide code support or code development support. This is an example of how API’s can be made useful for automating certain tasks. The customers can modify the code in order to get desired output.


Author & Company Bio

Mahaswin Ramalingam Balaji is a Technical Account Manager at AWS and a certified Subject Matter Expert in AWS Quick. Mahaswin is interested in Data visualization, Data engineering and in enhancing the features of Quick Sight.

Amazon Web Services (AWS) is the world’s most comprehensive and broadly adopted cloud, offering over 200 fully featured services from data centers globally. Millions of customers—including the fastest-growing startups, largest enterprises, and leading government agencies—are using AWS to lower costs, become more agile, and innovate faster.

1 Like