ruby/example_code/iam/iam-ruby-example-manage-policies.rb
def policy_detached_from_role?(iam_client, role_name, policy_arn)
  iam_client.detach_role_policy(role_name: role_name, policy_arn: policy_arn)
  return true
rescue StandardError => e
  puts "Error detaching policy from role: #{e.message}"
  return false
end
# Detaches a policy from a role in AWS Identity and Access Management (IAM).
#
# Prerequisites:
# - An existing role with an attached policy.
#
# @param iam_client [Aws::IAM::Client] An initialized IAM client.
# @param role_name [String] The name of the role to detach the policy from.
# @param policy_arn [String] The policy's Amazon Resource Name (ARN).
# @return [Boolean] True if the policy was detached from the role;
#   otherwise, false.
# @example
#   exit 1 unless policy_detached_from_role?(
#     Aws::IAM::Client.new,
#     'my-role',
#     'arn:aws:iam::111111111111:policy/my-policy'
#   )

Detaches a policy from a role in AWS Identity and Access Management (IAM).
Prerequisites:
An existing role with an attached policy.
Detaches a policy from a role in AWS Identity and Access Management ( IAM ) . Prerequisites : An existing role with an attached policy .
def policy_detached_from_role?(iam_client, role_name, policy_arn)
  iam_client.detach_role_policy(role_name: role_name, policy_arn: policy_arn)
  return true
rescue StandardError => e
  puts "Error detaching policy from role: #{e.message}"
  return false
end
def policy_detached_from_role? ( iam_client , role_name , policy_arn ) iam_client . detach_role_policy ( role_name : role_name , policy_arn : policy_arn ) return true rescue StandardError => e puts "Error detaching policy from role: #{e.message}" return false end
Detaches a policy from a role in AWS Identity and Access Management (IAM).
Detaches a policy from a role in AWS Identity and Access Management ( IAM ) .
True if the policy was detached from the role; otherwise, false.
True if the policy was detached from the role ; otherwise false .
Boolean
iam_client
An initialized IAM client.
An initialized IAM client .
role_name
The name of the role to detach the policy from.
The name of the role to detach the policy from .
policy_arn
The policy's Amazon Resource Name (ARN).
The policy ' s Amazon Resource Name ( ARN ) .
example
exit 1 unless policy_detached_from_role?( Aws::IAM::Client.new, 'my-role', 'arn:aws:iam::111111111111:policy/my-policy' )
exit 1 unless policy_detached_from_role? ( Aws :: IAM :: Client . new ' my - role ' ' arn : aws : iam :: 111111111111 : policy / my - policy ' )