class Kitchen::Driver::Aws::Client

A class for creating and managing the EC2 client connection

@author Tyler Ball <tball@chef.io>

Public Class Methods

new( region, profile_name = "default", http_proxy = nil, retry_limit = nil, ssl_verify_peer = true ) click to toggle source
# File lib/kitchen/driver/aws/client.rb, line 31
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

Public Instance Methods

client() click to toggle source
# File lib/kitchen/driver/aws/client.rb, line 81
def client
  @client ||= ::Aws::EC2::Client.new
end
create_instance(options) click to toggle source

create a new AWS EC2 instance @param options [Hash] has of instance options @see docs.aws.amazon.com/sdkforruby/api/Aws/EC2/Resource.html#create_instances-instance_method @return [Aws::EC2::Instance]

# File lib/kitchen/driver/aws/client.rb, line 51
def create_instance(options)
  resource.create_instances(options).first
end
get_instance(id) click to toggle source

get an instance object given an id @param id [String] aws instance id @return [Aws::EC2::Instance]

# File lib/kitchen/driver/aws/client.rb, line 58
def get_instance(id)
  resource.instance(id)
end
get_instance_from_spot_request(request_id) click to toggle source

get an instance object given a spot request ID @param request_id [String] aws spot instance id @return [Aws::EC2::Instance]

# File lib/kitchen/driver/aws/client.rb, line 65
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) click to toggle source

check if instance exists, given an id @param id [String] aws instance id @return boolean

# File lib/kitchen/driver/aws/client.rb, line 77
def instance_exists?(id)
  resource.instance(id).exists?
end
resource() click to toggle source
# File lib/kitchen/driver/aws/client.rb, line 85
def resource
  @resource ||= ::Aws::EC2::Resource.new
end