Class: AWS::EC2::KeyPair

Inherits:
Resource
  • Object
show all
Defined in:
lib/aws/ec2/key_pair.rb

Overview

Represents an EC2 key pair.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ KeyPair

Returns a new instance of KeyPair.



22
23
24
25
26
27
# File 'lib/aws/ec2/key_pair.rb', line 22

def initialize name, options = {}
  @name = name.to_s
  @fingerprint = options[:fingerprint]
  @private_key = options[:private_key]
  super
end

Instance Attribute Details

#nameString (readonly)

Returns The name of the key pair.

Returns:

  • (String)

    The name of the key pair.



30
31
32
# File 'lib/aws/ec2/key_pair.rb', line 30

def name
  @name
end

Instance Method Details

#deletetrue

Deletes this key pair from EC2.

Returns:

  • (true)


61
62
63
64
# File 'lib/aws/ec2/key_pair.rb', line 61

def delete
  client.delete_key_pair(:key_name => name)  
  true
end

#exists?Boolean

Returns True if the key pair exists.

Returns:

  • (Boolean)

    True if the key pair exists.



33
34
35
36
37
# File 'lib/aws/ec2/key_pair.rb', line 33

def exists?
  !client.describe_key_pairs(:filters => [{ :name => "key-name",
                                          :values => [name] }]).
    key_set.empty?
end

#fingerprintString

Returns A SHA-1 digest of the DER encoded private key.

Returns:

  • (String)

    A SHA-1 digest of the DER encoded private key



40
# File 'lib/aws/ec2/key_pair.rb', line 40

def fingerprint; end

#private_keyString

Note:

Only call this method on newly created keys.

Returns the private key. Raises an exception if called against an existing key. You can only get the private key at the time of creation.

Returns:

  • (String)

    An unencrypted PEM encoded RSA private key.

See Also:



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

def private_key
  unless @private_key
    raise 'you can only get the private key for just-created keypairs'
  end
  @private_key
end