ruby/example_code/iam/iam-ruby-example-manage-policies.rb
# Displays a list of policy Amazon Resource Names (ARNs) that are attached to a
# role in AWS Identity and Access Management (IAM).
#
# Prerequisites:
# - An existing role.
#
# @param iam_client [Aws::IAM::Client] An initialized IAM client.
# @param role_name [String] The name of the role.
# @example
#   list_policy_arns_attached_to_role(Aws::IAM::Client.new, 'my-role')

Displays a list of policy Amazon Resource Names (ARNs) that are attached to a
role in AWS Identity and Access Management (IAM).

An existing role.
Displays a list of policy Amazon Resource Names ( ARNs ) that are attached to a role in AWS Identity and Access Management ( IAM ) . An existing role .
def list_policy_arns_attached_to_role(iam_client, role_name)
  response = iam_client.list_attached_role_policies(role_name: role_name)
  if response.key?('attached_policies') && response.attached_policies.count.positive?
    response.attached_policies.each do |attached_policy|
      puts "  #{attached_policy.policy_arn}"
    end
  else
    puts 'No policies attached to role.'
  end
rescue StandardError => e
  puts "Error checking for policies attached to role: #{e.message}"
end
def list_policy_arns_attached_to_role ( iam_client , role_name ) response = iam_client . list_attached_role_policies ( role_name : role_name ) if response . key? ( 'attached_policies' ) && response . attached_policies . count . positive? response . attached_policies . each do | attached_policy | puts "  #{attached_policy.policy_arn}" end else puts 'No policies attached to role.' end rescue StandardError => e puts "Error checking for policies attached to role: #{e.message}" end
Displays a list of policy Amazon Resource Names (ARNs) that are attached to a
role in AWS Identity and Access Management (IAM).
Displays a list of policy Amazon Resource Names ( ARNs ) that are attached to a role in AWS Identity and Access Management ( IAM ) .
iam_client
An initialized IAM client.
An initialized IAM client .
role_name
The name of the role.
The name of the role .
example
None