def create_members()

in enableDetective.py [0:0]


def create_members(d_client: botocore.client.BaseClient, graph_arn: str, disable_email: bool, account_ids: typing.Set[str],
                   account_csv: typing.Dict[str, str]) -> typing.Set[str]:
    """
    Creates member accounts for all accounts in the csv that are not present in the graph member set.

    Args:
        - d_client: Detective boto3 client generated from the master session.
        - graph_arn: Graph to add members to.
        - account_ids: Already present account ids in the graph.
        - account_csv: Accounts read from the CSV input file.

    Returns:
        Set with the IDs of the successfully created accounts.
    """
    try:
        # I'm calculating set difference: the elements that are present in the CSV and that are not
        # present in the account_ids set.
        set_difference = account_csv.keys() - account_ids
        if not set_difference:
            logging.info(f'No new members to create in graph {graph_arn}.')
            return set()

        logging.info(f'Creating member accounts in graph {graph_arn} '
                    f'for accounts {", ".join(set_difference)}.')

        new_members = [{'AccountId': x, 'EmailAddress': account_csv[x]}
                    for x in set_difference]
        response = d_client.create_members(GraphArn=graph_arn,
                                        Message='Automatically generated invitation',
                                        Accounts=new_members,
                                        DisableEmailNotification=disable_email)
        for error in response['UnprocessedAccounts']:
            logging.exception(f'Could not create member for account {error["AccountId"]} in '
                            f'graph {graph_arn}: {error["Reason"]}')
    except Exception as e:
        logging.exception(f'exception when getting memebers: {e}')
    return {x['AccountId'] for x in response['Members']}