Class: Kitchen::Driver::Aws::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/kitchen/driver/aws/client.rb

Overview

A class for creating and managing the EC2 client connection

Author:

Instance Method Summary collapse

Constructor Details

#initialize(region, profile_name = "default", http_proxy = nil, retry_limit = nil, ssl_verify_peer = true) ⇒ Client

Configure the AWS SDK for this driver's connection settings.

These settings are applied to the SDK's process-wide configuration rather than held on this object, so clients built later pick them up. A nil retry limit is omitted rather than written, so that the SDK's own default survives.

Parameters:

  • region (String)

    the AWS region, e.g. "us-west-2"

  • profile_name (String) (defaults to: "default")

    shared credentials profile to use

  • http_proxy (String, nil) (defaults to: nil)

    proxy URL, if any

  • retry_limit (Integer, nil) (defaults to: nil)

    SDK retry limit, or nil for the default

  • ssl_verify_peer (Boolean) (defaults to: true)

    whether to verify TLS peers



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/kitchen/driver/aws/client.rb', line 46

def initialize(
  region,
  profile_name = "default",
  http_proxy = nil,
  retry_limit = nil,
  ssl_verify_peer = true
)
  ::Aws.config.update(
    region:,
    profile: profile_name,
    http_proxy:,
    ssl_verify_peer:
  )
  ::Aws.config.update(retry_limit:) unless retry_limit.nil?
end

Instance Method Details

#clientAws::EC2::Client

The low-level EC2 client, for API calls with no resource equivalent.

Returns:

  • (Aws::EC2::Client)


99
100
101
# File 'lib/kitchen/driver/aws/client.rb', line 99

def client
  @client ||= ::Aws::EC2::Client.new
end

#create_instance(options) ⇒ Aws::EC2::Instance

create a new AWS EC2 instance

Parameters:

  • options (Hash)

    has of instance options

Returns:

  • (Aws::EC2::Instance)

See Also:



66
67
68
# File 'lib/kitchen/driver/aws/client.rb', line 66

def create_instance(options)
  resource.create_instances(options).first
end

#get_instance(id) ⇒ Aws::EC2::Instance

get an instance object given an id

Parameters:

  • id (String)

    aws instance id

Returns:

  • (Aws::EC2::Instance)


73
74
75
# File 'lib/kitchen/driver/aws/client.rb', line 73

def get_instance(id)
  resource.instance(id)
end

#get_instance_from_spot_request(request_id) ⇒ Aws::EC2::Instance

get an instance object given a spot request ID

Parameters:

  • request_id (String)

    aws spot instance id

Returns:

  • (Aws::EC2::Instance)


80
81
82
83
84
85
86
87
# File 'lib/kitchen/driver/aws/client.rb', line 80

def get_instance_from_spot_request(request_id)
  resource.instances(
    filters: [{
      name: "spot-instance-request-id",
      values: [request_id],
    }]
  ).to_a[0]
end

#instance_exists?(id) ⇒ Boolean

check if instance exists, given an id

Parameters:

  • id (String)

    aws instance id

Returns:

  • (Boolean)


92
93
94
# File 'lib/kitchen/driver/aws/client.rb', line 92

def instance_exists?(id)
  resource.instance(id).exists?
end

#resourceAws::EC2::Resource

The EC2 resource interface, for working with instances and images as objects rather than raw API responses.

Returns:

  • (Aws::EC2::Resource)


107
108
109
# File 'lib/kitchen/driver/aws/client.rb', line 107

def resource
  @resource ||= ::Aws::EC2::Resource.new
end