def remove_iam_binding(policy, member, role):
  """Removes binding from given policy.

  Args:
    policy: Policy.
    member: Account, e.g. user:joe@doe.com, serviceAccount:..., etc.
    role: Role

  Returns:
    True if binding was removed. False, if binding was not present in policy.
  """
  # Check if member is already bound to the role and remove it
  for binding in policy['bindings']:
    if binding['role'] == role:
      if member in binding['members']:
        # Member is bound to role. Remove it.
        binding['members'].remove(member)
        # Remove binding altogether if no more members left.
        if not binding['members']:
          policy['bindings'].remove(binding)
        return True

  return False