ruby/example_code/ec2/ec2-ruby-example-key-pairs.rb
# Displays information about available key pairs in
# Amazon Elastic Compute Cloud (Amazon EC2).
#
# @param ec2_client [Aws::EC2::Client] An initialized EC2 client.
# @example
#   describe_key_pairs(Aws::EC2::Client.new(region: 'us-west-2'))

Displays information about available key pairs in
Amazon Elastic Compute Cloud (Amazon EC2).
Displays information about available key pairs in Amazon Elastic Compute Cloud ( Amazon EC2 ) .
def describe_key_pairs(ec2_client)
  result = ec2_client.describe_key_pairs
  if result.key_pairs.count.zero?
    puts 'No key pairs found.'
  else
    puts 'Key pair names:'
    result.key_pairs.each do |key_pair|
      puts key_pair.key_name
    end
  end
rescue StandardError => e
  puts "Error getting information about key pairs: #{e.message}"
end
def describe_key_pairs ( ec2_client ) result = ec2_client . describe_key_pairs if result . key_pairs . count . zero? puts 'No key pairs found.' else puts 'Key pair names:' result . key_pairs . each do | key_pair | puts key_pair . key_name end end rescue StandardError => e puts "Error getting information about key pairs: #{e.message}" end
Displays information about available key pairs in
Amazon Elastic Compute Cloud (Amazon EC2).
Displays information about available key pairs in Amazon Elastic Compute Cloud ( Amazon EC2 ) .
ec2_client
An initialized EC2 client.
An initialized EC2 client .
example
None