ruby/example_code/iam/iam-ruby-example-access-keys.rb
def access_keys_last_used(iam, user_name)
  response = iam.list_access_keys(user_name: user_name)

  response.access_key_metadata.each do |key_metadata|
    last_used = iam.get_access_key_last_used(access_key_id: key_metadata.access_key_id)
    if last_used.access_key_last_used.last_used_date.nil?
      puts "  Key '#{key_metadata.access_key_id}' not used or date undetermined."
    else
      puts "  Key '#{key_metadata.access_key_id}' last used on " \
      "#{last_used.access_key_last_used.last_used_date}"
    end
  end
rescue StandardError => e
  puts "Error determining when access keys were last used: #{e.message}"
end
# Lists information about when access keys for a user in
# AWS Identity and Access Management (IAM) were last used.
#
# Prerequisites:
# - The user in IAM.
#
# @param iam [Aws::IAM::Client] An initialized IAM client.
# @param user_name [String] The name of the user.
# @example
#   puts access_keys_last_used(Aws::IAM::Client.new, 'my-user')

Lists information about when access keys for a user in
AWS Identity and Access Management (IAM) were last used.

The user in IAM.
Lists information about when access keys for a user in AWS Identity and Access Management ( IAM ) were last used . The user in IAM .
def access_keys_last_used(iam, user_name)
  response = iam.list_access_keys(user_name: user_name)
  response.access_key_metadata.each do |key_metadata|
    last_used = iam.get_access_key_last_used(access_key_id: key_metadata.access_key_id)
    if last_used.access_key_last_used.last_used_date.nil?
      puts "  Key '#{key_metadata.access_key_id}' not used or date undetermined."
    else
      puts "  Key '#{key_metadata.access_key_id}' last used on " \
      "#{last_used.access_key_last_used.last_used_date}"
    end
  end
rescue StandardError => e
  puts "Error determining when access keys were last used: #{e.message}"
end
def access_keys_last_used ( iam , user_name ) response = iam . list_access_keys ( user_name : user_name ) response . access_key_metadata . each do | key_metadata | last_used = iam . get_access_key_last_used ( access_key_id : key_metadata . access_key_id ) if last_used . access_key_last_used . last_used_date . nil? puts "  Key '#{key_metadata.access_key_id}' not used or date undetermined." else puts "  Key '#{key_metadata.access_key_id}' last used on " "#{last_used.access_key_last_used.last_used_date}" end end rescue StandardError => e puts "Error determining when access keys were last used: #{e.message}" end
Lists information about when access keys for a user in
AWS Identity and Access Management (IAM) were last used.
Lists information about when access keys for a user in AWS Identity and Access Management ( IAM ) were last used .
iam
An initialized IAM client.
An initialized IAM client .
user_name
The name of the user.
The name of the user .
example
puts access_keys_last_used(Aws::IAM::Client.new, 'my-user')
puts access_keys_last_used ( Aws :: IAM :: Client . new ' my - user ' )