ruby/example_code/ec2/ec2-ruby-example-key-pairs.rb
# Deletes a key pair in Amazon Elastic Compute Cloud (Amazon EC2).
#
# Prerequisites:
#
# - The key pair to delete.
#
# @param ec2_client [Aws::EC2::Client] An initialized EC2 client.
# @param key_pair_name [String] The name of the key pair to delete.
# @return [Boolean] true if the key pair was deleted; otherwise, false.
# @example
#   exit 1 unless key_pair_deleted?(
#     Aws::EC2::Client.new(region: 'us-west-2'),
#     'my-key-pair'
#   )

Deletes a key pair in Amazon Elastic Compute Cloud (Amazon EC2).
Prerequisites.

The key pair to delete.
Deletes a key pair in Amazon Elastic Compute Cloud ( Amazon EC2 ) . Prerequisites . The key pair to delete .
def key_pair_deleted?(ec2_client, key_pair_name)
  ec2_client.delete_key_pair(key_name: key_pair_name)
  return true
rescue StandardError => e
  puts "Error deleting key pair: #{e.message}"
  return false
end
def key_pair_deleted? ( ec2_client , key_pair_name ) ec2_client . delete_key_pair ( key_name : key_pair_name ) return true rescue StandardError => e puts "Error deleting key pair: #{e.message}" return false end
Deletes a key pair in Amazon Elastic Compute Cloud (Amazon EC2).
Deletes a key pair in Amazon Elastic Compute Cloud ( Amazon EC2 ) .
true if the key pair was deleted; otherwise, false.
true if the key pair was deleted ; otherwise false .
Boolean
ec2_client
An initialized EC2 client.
An initialized EC2 client .
key_pair_name
The name of the key pair to delete.
The name of the key pair to delete .
example
exit 1 unless key_pair_deleted?( Aws::EC2::Client.new(region: 'us-west-2'), 'my-key-pair' )
exit 1 unless key_pair_deleted? ( Aws :: EC2 :: Client . new ( region : ' us - west - 2 ' ) ' my - key - pair ' )