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