Class: AWS::EC2::KeyPairCollection

Inherits:
Collection
  • Object
show all
Defined in:
lib/aws/ec2/key_pair_collection.rb

Overview

Represents all key pairs in your account. You can use this collection to create, import and find key pairs.

Instance Method Summary collapse

Instance Method Details

#[](key_name) ⇒ KeyPair

Returns key_name The name of the key pair.

Returns:

  • (KeyPair)

    key_name The name of the key pair.



60
61
62
# File 'lib/aws/ec2/key_pair_collection.rb', line 60

def [] key_name
  super
end

#create(key_name) ⇒ KeyPair

Returns a new key pair.

Parameters:

  • key_name (String)

    A name for the key pair.

Returns:

  • (KeyPair)

    Returns a new key pair.



29
30
31
# File 'lib/aws/ec2/key_pair_collection.rb', line 29

def create key_name
  create_or_import(:create_key_pair, :key_name => key_name)
end

#each(&block) ⇒ nil

Yields once for each key pair in your account.

Returns:

  • (nil)


66
67
68
69
70
71
72
73
74
# File 'lib/aws/ec2/key_pair_collection.rb', line 66

def each &block
  response = filtered_request(:describe_key_pairs)
  response.key_set.each do |kp|
    yield(KeyPair.new(kp.key_name,
                      :fingerprint => kp.key_fingerprint,
                      :config => config))
  end
  nil
end

#import(key_name, public_key) ⇒ KeyPair

Imports the public key from an RSA key pair that you created with a third-party tool. Compare this with #create, in which EC2 creates the key pair and gives the keys to you (EC2 keeps a copy of the public key). With ImportKeyPair, you create the key pair and give EC2 just the public key. The private key is never transferred between you and EC2.

Supported formats:

  • OpenSSH public key format (e.g., the format in ~/.ssh/authorized_keys)

  • Base64 encoded DER format

  • SSH public key file format as specified in RFC4716

DSA keys are not supported. Make sure your key generator is set up to create RSA keys. Supported lengths: 1024, 2048, and 4096.

Parameters:

  • key_name (String)

    A name for this key pair.

  • public_key (String)

    The RSA public key.

Returns:

  • (KeyPair)

    Returns a new key pair.



53
54
55
56
57
# File 'lib/aws/ec2/key_pair_collection.rb', line 53

def import key_name, public_key
  create_or_import(:import_key_pair, 
    :key_name => key_name,
    :public_key_material => Base64.encode64(public_key.to_s))
end