ruby/example_code/iam/iam-ruby-example-access-keys.rb
def create_access_key(iam, user_name)
  response = iam.create_access_key(user_name: user_name)
  access_key = response.access_key
  puts 'Access key created:'
  puts "  Access key ID: #{access_key.access_key_id}"
  puts "  Secret access key: #{access_key.secret_access_key}"
  puts 'Keep a record of this information in a secure location. ' \
    'This will be the only time you will be able to view the ' \
    'secret access key.'
  return access_key
rescue Aws::IAM::Errors::LimitExceeded
  puts 'Error creating access key: limit exceeded. Cannot create any more. ' \
    'To create more, delete an existing access key, and then try again.'
  return 'Error'
rescue StandardError => e
  puts "Error creating access key: #{e.message}"
  return 'Error'
end
# Creates an access key for a user in AWS Identity and Access Management (IAM).
#
# Prerequisites:
# - The user in IAM.
#
# @param iam [Aws::IAM::Client] An initialized IAM client.
# @param user_name [String] The name of the user.
# @return [Aws::IAM::Types::AccessKey] Information about the new access key;
#   otherwise, the string 'Error'.
# @example
#   puts create_access_key(Aws::IAM::Client.new, 'my-user')

Creates an access key for a user in AWS Identity and Access Management (IAM).
Prerequisites:
The user in IAM.
Creates an access key for a user in AWS Identity and Access Management ( IAM ) . Prerequisites : The user in IAM .
def create_access_key(iam, user_name)
  response = iam.create_access_key(user_name: user_name)
  access_key = response.access_key
  puts 'Access key created:'
  puts "  Access key ID: #{access_key.access_key_id}"
  puts "  Secret access key: #{access_key.secret_access_key}"
  puts 'Keep a record of this information in a secure location. ' \
    'This will be the only time you will be able to view the ' \
    'secret access key.'
  return access_key
rescue Aws::IAM::Errors::LimitExceeded
  puts 'Error creating access key: limit exceeded. Cannot create any more. ' \
    'To create more, delete an existing access key, and then try again.'
  return 'Error'
rescue StandardError => e
  puts "Error creating access key: #{e.message}"
  return 'Error'
end
def create_access_key ( iam , user_name ) response = iam . create_access_key ( user_name : user_name ) access_key = response . access_key puts 'Access key created:' puts "  Access key ID: #{access_key.access_key_id}" puts "  Secret access key: #{access_key.secret_access_key}" puts 'Keep a record of this information in a secure location. ' 'This will be the only time you will be able to view the ' 'secret access key.' return access_key rescue Aws :: IAM :: Errors :: LimitExceeded puts 'Error creating access key: limit exceeded. Cannot create any more. ' 'To create more, delete an existing access key, and then try again.' return 'Error' rescue StandardError => e puts "Error creating access key: #{e.message}" return 'Error' end
Creates an access key for a user in AWS Identity and Access Management (IAM).
Creates an access key for a user in AWS Identity and Access Management ( IAM ) .
Information about the new access key; otherwise, the string 'Error'.
Information about the new access key ; otherwise the string ' Error ' .
Aws::IAM::Types::AccessKey
iam
An initialized IAM client.
An initialized IAM client .
user_name
The name of the user.
The name of the user .
example
puts create_access_key(Aws::IAM::Client.new, 'my-user')
puts create_access_key ( Aws :: IAM :: Client . new ' my - user ' )