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
# File 'lib/aws/ec2/key_pair.rb', line 22

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

Instance Attribute Details

#fingerprintString (readonly)

A SHA-1 digest of the DER encoded private key

Returns:

  • (String)

    the current value of fingerprint



20
21
22
# File 'lib/aws/ec2/key_pair.rb', line 20

def fingerprint
  @fingerprint
end

#nameString (readonly)

Returns The name of the key pair.

Returns:

  • (String)

    The name of the key pair.



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

def name
  @name
end

Instance Method Details

#deletetrue

Deletes this key pair from EC2.

Returns:

  • (true)


65
66
67
68
# File 'lib/aws/ec2/key_pair.rb', line 65

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.



42
43
44
45
46
47
# File 'lib/aws/ec2/key_pair.rb', line 42

def exists?
  resp = client.describe_key_pairs(:filters => [
    { :name => "key-name", :values => [name] }
  ])
  !resp.key_set.empty?
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:



56
57
58
59
60
61
# File 'lib/aws/ec2/key_pair.rb', line 56

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