def add_members_to_policy(role: str, iam_policy: list, members: list, command_name: str) -> list:
    """
    Append members to policy role members.
    Args:
        role (str): The name of policy role.
        iam_policy (list): IAM policies.
        members (list): Members to append to policy.
        command_name (str): An alternative  command that will be displayed to the user in case of an error.

    Returns:
        list: Updated policies.

    """
    role_found = False
    for policy in iam_policy:
        if policy.get('role') == role:
            policy['members'].extend(members)
            role_found = True
            break

    if not role_found:
        raise Exception('The provided role is not part of the project IAM policies.'
                        f'If you wish to add a new policy, consider using the {command_name} command.')

    return iam_policy