ruby/example_code/s3/auth_session_token_request_test.rb
# Checks whether a role exists in IAM.
#
# @param iam_client [Aws::IAM::Client] An initialized IAM client.
# @param role_name [String] The role's name.
# @return [Boolean] true if the role exists; otherwise, false.
# @example
#   iam_client = Aws::IAM::Client.new(region: 'us-west-2')
#   exit 1 unless role_exists?(iam_client, 'my-role')
Checks whether a role exists in IAM.
Checks whether a role exists in IAM .
def role_exists?(iam_client, role_name)
  response = iam_client.get_role(role_name: role_name)
  return true if response.role.role_name
rescue StandardError => e
  puts 'Error while determining whether the role ' \
    "'#{role_name}' exists: #{e.message}"
end
def role_exists? ( iam_client , role_name ) response = iam_client . get_role ( role_name : role_name ) return true if response . role . role_name rescue StandardError => e puts 'Error while determining whether the role ' "'#{role_name}' exists: #{e.message}" end
Checks whether a role exists in IAM.
Checks whether a role exists in IAM .
true if the role exists; otherwise, false.
true if the role exists ; otherwise false .
Boolean
iam_client
An initialized IAM client.
An initialized IAM client .
role_name
The role's name.
The role ' s name .
example
iam_client = Aws::IAM::Client.new(region: 'us-west-2') exit 1 unless role_exists?(iam_client, 'my-role')
iam_client = Aws :: IAM :: Client . new ( region : ' us - west - 2 ' ) exit 1 unless role_exists? ( iam_client ' my - role ' )