You are viewing documentation for version 3 of the AWS SDK for Ruby. Version 2 documentation can be found here.

Class: Aws::EC2::Instance

Inherits:
Object
  • Object
show all
Defined in:
gems/aws-sdk-ec2/lib/aws-sdk-ec2/customizations/instance.rb,
gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb

Defined Under Namespace

Classes: Collection

Actions collapse

Associations collapse

Read-Only Attributes collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, options = {}) ⇒ Instance #initialize(options = {}) ⇒ Instance

Returns a new instance of Instance

Overloads:

  • #initialize(id, options = {}) ⇒ Instance

    Parameters:

    • id (String)

    Options Hash (options):

  • #initialize(options = {}) ⇒ Instance

    Options Hash (options):

    • :id (required, String)
    • :client (Client)


19
20
21
22
23
24
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 19

def initialize(*args)
  options = Hash === args.last ? args.pop.dup : {}
  @id = extract_id(args, options)
  @data = options.delete(:data)
  @client = options.delete(:client) || Client.new(options)
end

Instance Method Details

#ami_launch_indexInteger

The AMI launch index, which can be used to find this instance in the launch group.

Returns:

  • (Integer)


37
38
39
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 37

def ami_launch_index
  data[:ami_launch_index]
end

#architectureString

The architecture of the image.

Returns:

  • (String)


164
165
166
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 164

def architecture
  data[:architecture]
end

Examples:

Request syntax with placeholder values


instance.attach_classic_link_vpc({
  dry_run: false,
  groups: ["String"], # required
  vpc_id: "String", # required
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

  • :groups (required, Array<String>)

    The ID of one or more of the VPC's security groups. You cannot specify security groups from a different VPC.

  • :vpc_id (required, String)

    The ID of a ClassicLink-enabled VPC.

Returns:



523
524
525
526
527
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 523

def attach_classic_link_vpc(options = {})
  options = options.merge(instance_id: @id)
  resp = @client.attach_classic_link_vpc(options)
  resp.data
end

#attach_volume(options = {}) ⇒ Types::VolumeAttachment

Examples:

Request syntax with placeholder values


instance.attach_volume({
  device: "String", # required
  volume_id: "String", # required
  dry_run: false,
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :device (required, String)

    The device name to expose to the instance (for example, /dev/sdh or xvdh).

  • :volume_id (required, String)

    The ID of the EBS volume. The volume and instance must be within the same Availability Zone.

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

Returns:



549
550
551
552
553
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 549

def attach_volume(options = {})
  options = options.merge(instance_id: @id)
  resp = @client.attach_volume(options)
  resp.data
end

#block_device_mappingsArray<Types::InstanceBlockDeviceMapping>

Any block device mapping entries for the instance.



170
171
172
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 170

def block_device_mappings
  data[:block_device_mappings]
end

#classic_addressClassicAddress?

Returns:



1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1169

def classic_address
  if data[:public_ip_address]
    ClassicAddress.new(
      public_ip: data[:public_ip_address],
      client: @client
    )
  else
    nil
  end
end

#clientClient

Returns:



289
290
291
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 289

def client
  @client
end

#client_tokenString

The idempotency token you provided when you launched the instance, if applicable.

Returns:

  • (String)


177
178
179
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 177

def client_token
  data[:client_token]
end

#console_output(options = {}) ⇒ Types::GetConsoleOutputResult

Examples:

Request syntax with placeholder values


instance.console_output({
  dry_run: false,
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

Returns:



567
568
569
570
571
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 567

def console_output(options = {})
  options = options.merge(instance_id: @id)
  resp = @client.get_console_output(options)
  resp.data
end

#create_image(options = {}) ⇒ Image

Examples:

Request syntax with placeholder values


image = instance.create_image({
  block_device_mappings: [
    {
      device_name: "String",
      virtual_name: "String",
      ebs: {
        encrypted: false,
        delete_on_termination: false,
        iops: 1,
        snapshot_id: "String",
        volume_size: 1,
        volume_type: "standard", # accepts standard, io1, gp2, sc1, st1
      },
      no_device: "String",
    },
  ],
  description: "String",
  dry_run: false,
  name: "String", # required
  no_reboot: false,
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :block_device_mappings (Array<Types::BlockDeviceMapping>)

    Information about one or more block device mappings.

  • :description (String)

    A description for the new image.

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

  • :name (required, String)

    A name for the new image.

    Constraints: 3-128 alphanumeric characters, parentheses (()), square brackets ([]), spaces ( ), periods (.), slashes (/), dashes (-), single quotes ('), at-signs (@), or underscores(_)

  • :no_reboot (Boolean)

    By default, Amazon EC2 attempts to shut down and reboot the instance before creating the image. If the 'No Reboot' option is set, Amazon EC2 doesn't shut down the instance before creating the image. When this option is used, file system integrity on the created image can't be guaranteed.

Returns:



619
620
621
622
623
624
625
626
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 619

def create_image(options = {})
  options = options.merge(instance_id: @id)
  resp = @client.create_image(options)
  Image.new(
    id: resp.data.image_id,
    client: @client
  )
end

#create_tags(options = {}) ⇒ Tag::Collection

Examples:

Request syntax with placeholder values


tag = instance.create_tags({
  dry_run: false,
  tags: [ # required
    {
      key: "String",
      value: "String",
    },
  ],
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

  • :tags (required, Array<Types::Tag>)

    One or more tags. The value parameter is required, but if you don't want the tag to have a value, specify the parameter with no value, and we set the value to an empty string.

Returns:



650
651
652
653
654
655
656
657
658
659
660
661
662
663
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 650

def create_tags(options = {})
  batch = []
  options = Aws::Util.deep_merge(options, resources: [@id])
  resp = @client.create_tags(options)
  options[:tags].each do |t|
    batch << Tag.new(
      resource_id: @id,
      key: t[:key],
      value: t[:value],
      client: @client
    )
  end
  Tag::Collection.new([batch], size: batch.size)
end

#dataTypes::Instance

Returns the data for this Aws::EC2::Instance. Calls Client#describe_instances if #data_loaded? is false.

Returns:



309
310
311
312
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 309

def data
  load unless @data
  @data
end

#data_loaded?Boolean

Returns true if this resource is loaded. Accessing attributes or #data on an unloaded resource will trigger a call to #load.

Returns:

  • (Boolean)

    Returns true if this resource is loaded. Accessing attributes or #data on an unloaded resource will trigger a call to #load.



317
318
319
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 317

def data_loaded?
  !!@data
end

#decrypt_windows_password(key_pair_path) ⇒ String

Parameters:

  • key_pair_path (String, Pathname)

Returns:

  • (String)


9
10
11
12
13
14
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/customizations/instance.rb', line 9

def decrypt_windows_password(key_pair_path)
  decoded = Base64.decode64(encrypted_password)
  pem_bytes = File.open(key_pair_path, 'rb') { |f| f.read }
  private_key = OpenSSL::PKey::RSA.new(pem_bytes)
  private_key.private_decrypt(decoded)
end

#describe_attribute(options = {}) ⇒ Types::InstanceAttribute

Examples:

Request syntax with placeholder values


instance.describe_attribute({
  attribute: "instanceType", # required, accepts instanceType, kernel, ramdisk, userData, disableApiTermination, instanceInitiatedShutdownBehavior, rootDeviceName, blockDeviceMapping, productCodes, sourceDestCheck, groupSet, ebsOptimized, sriovNetSupport, enaSupport
  dry_run: false,
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :attribute (required, String)

    The instance attribute.

    Note: The enaSupport attribute is not supported at this time.

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

Returns:



682
683
684
685
686
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 682

def describe_attribute(options = {})
  options = options.merge(instance_id: @id)
  resp = @client.describe_instance_attribute(options)
  resp.data
end

Examples:

Request syntax with placeholder values


instance.detach_classic_link_vpc({
  dry_run: false,
  vpc_id: "String", # required
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

  • :vpc_id (required, String)

    The ID of the VPC to which the instance is linked.

Returns:



703
704
705
706
707
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 703

def detach_classic_link_vpc(options = {})
  options = options.merge(instance_id: @id)
  resp = @client.detach_classic_link_vpc(options)
  resp.data
end

#detach_volume(options = {}) ⇒ Types::VolumeAttachment

Examples:

Request syntax with placeholder values


instance.detach_volume({
  device: "String",
  force: false,
  volume_id: "String", # required
  dry_run: false,
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :device (String)

    The device name.

  • :force (Boolean)

    Forces detachment if the previous detachment attempt did not occur cleanly (for example, logging into an instance, unmounting the volume, and detaching normally). This option can lead to data loss or a corrupted file system. Use this option only as a last resort to detach a volume from a failed instance. The instance won't have an opportunity to flush file system caches or file system metadata. If you use this option, you must perform file system check and repair procedures.

  • :volume_id (required, String)

    The ID of the volume.

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

Returns:



737
738
739
740
741
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 737

def detach_volume(options = {})
  options = options.merge(instance_id: @id)
  resp = @client.detach_volume(options)
  resp.data
end

#ebs_optimizedBoolean

Indicates whether the instance is optimized for Amazon EBS I/O. This optimization provides dedicated throughput to Amazon EBS and an optimized configuration stack to provide optimal I/O performance. This optimization isn't available with all instance types. Additional usage charges apply when using an EBS Optimized instance.

Returns:

  • (Boolean)


187
188
189
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 187

def ebs_optimized
  data[:ebs_optimized]
end

#elastic_gpu_associationsArray<Types::ElasticGpuAssociation>

The Elastic GPU associated with the instance.

Returns:



217
218
219
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 217

def elastic_gpu_associations
  data[:elastic_gpu_associations]
end

#ena_supportBoolean

Specifies whether enhanced networking with ENA is enabled.

Returns:

  • (Boolean)


193
194
195
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 193

def ena_support
  data[:ena_support]
end

#exists?(options = {}) ⇒ Boolean

Returns true if the Instance exists.

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Returns:

  • (Boolean)

    Returns true if the Instance exists.



324
325
326
327
328
329
330
331
332
333
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 324

def exists?(options = {})
  begin
    wait_until_exists(options.merge(max_attempts: 1))
    true
  rescue Aws::Waiters::Errors::UnexpectedError => e
    raise e.error
  rescue Aws::Waiters::Errors::WaiterFailed
    false
  end
end

#hypervisorString

The hypervisor type of the instance.

Returns:

  • (String)


199
200
201
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 199

def hypervisor
  data[:hypervisor]
end

#iam_instance_profileTypes::IamInstanceProfile

The IAM instance profile associated with the instance, if applicable.



205
206
207
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 205

def iam_instance_profile
  data[:iam_instance_profile]
end

#idString Also known as: instance_id

Returns:

  • (String)


29
30
31
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 29

def id
  @id
end

#imageImage?

Returns:



1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1181

def image
  if data[:image_id]
    Image.new(
      id: data[:image_id],
      client: @client
    )
  else
    nil
  end
end

#image_idString

The ID of the AMI used to launch the instance.

Returns:

  • (String)


43
44
45
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 43

def image_id
  data[:image_id]
end

#instance_lifecycleString

Indicates whether this is a Spot Instance or a Scheduled Instance.

Returns:

  • (String)


211
212
213
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 211

def instance_lifecycle
  data[:instance_lifecycle]
end

#instance_typeString

The instance type.

Returns:

  • (String)


49
50
51
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 49

def instance_type
  data[:instance_type]
end

#kernel_idString

The kernel associated with this instance, if applicable.

Returns:

  • (String)


55
56
57
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 55

def kernel_id
  data[:kernel_id]
end

#key_nameString

The name of the key pair, if this instance was launched with an associated key pair.

Returns:

  • (String)


62
63
64
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 62

def key_name
  data[:key_name]
end

#key_pairKeyPairInfo?

Returns:



1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1193

def key_pair
  if data[:key_name]
    KeyPairInfo.new(
      name: data[:key_name],
      client: @client
    )
  else
    nil
  end
end

#launch_timeTime

The time the instance was launched.

Returns:

  • (Time)


68
69
70
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 68

def launch_time
  data[:launch_time]
end

#loadself Also known as: reload

Loads, or reloads #data for the current Aws::EC2::Instance. Returns self making it possible to chain methods.

instance.reload.data

Returns:

  • (self)


299
300
301
302
303
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 299

def load
  resp = @client.describe_instances(instance_ids: [@id])
  @data = resp.reservations[0].instances[0]
  self
end

#modify_attribute(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


instance.modify_attribute({
  source_dest_check: {
    value: false,
  },
  attribute: "instanceType", # accepts instanceType, kernel, ramdisk, userData, disableApiTermination, instanceInitiatedShutdownBehavior, rootDeviceName, blockDeviceMapping, productCodes, sourceDestCheck, groupSet, ebsOptimized, sriovNetSupport, enaSupport
  block_device_mappings: [
    {
      device_name: "String",
      ebs: {
        delete_on_termination: false,
        volume_id: "String",
      },
      no_device: "String",
      virtual_name: "String",
    },
  ],
  disable_api_termination: {
    value: false,
  },
  dry_run: false,
  ebs_optimized: {
    value: false,
  },
  ena_support: {
    value: false,
  },
  groups: ["String"],
  instance_initiated_shutdown_behavior: "value", # value <Hash,Array,String,Numeric,Boolean,IO,Set,nil>
  instance_type: "value", # value <Hash,Array,String,Numeric,Boolean,IO,Set,nil>
  kernel: "value", # value <Hash,Array,String,Numeric,Boolean,IO,Set,nil>
  ramdisk: "value", # value <Hash,Array,String,Numeric,Boolean,IO,Set,nil>
  sriov_net_support: "value", # value <Hash,Array,String,Numeric,Boolean,IO,Set,nil>
  user_data: {
    value: "data",
  },
  value: "String",
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :source_dest_check (Types::AttributeBooleanValue)

    Specifies whether source/destination checking is enabled. A value of true means that checking is enabled, and false means that checking is disabled. This value must be false for a NAT instance to perform NAT.

  • :attribute (String)

    The name of the attribute.

  • :block_device_mappings (Array<Types::InstanceBlockDeviceMappingSpecification>)

    Modifies the DeleteOnTermination attribute for volumes that are currently attached. The volume must be owned by the caller. If no value is specified for DeleteOnTermination, the default is true and the volume is deleted when the instance is terminated.

    To add instance store volumes to an Amazon EBS-backed instance, you must add them when you launch the instance. For more information, see Updating the Block Device Mapping when Launching an Instance in the Amazon Elastic Compute Cloud User Guide.

  • :disable_api_termination (Types::AttributeBooleanValue)

    If the value is true, you can't terminate the instance using the Amazon EC2 console, CLI, or API; otherwise, you can. You cannot use this parameter for Spot Instances.

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

  • :ebs_optimized (Types::AttributeBooleanValue)

    Specifies whether the instance is optimized for Amazon EBS I/O. This optimization provides dedicated throughput to Amazon EBS and an optimized configuration stack to provide optimal EBS I/O performance. This optimization isn't available with all instance types. Additional usage charges apply when using an EBS Optimized instance.

  • :ena_support (Types::AttributeBooleanValue)

    Set to true to enable enhanced networking with ENA for the instance.

    This option is supported only for HVM instances. Specifying this option with a PV instance can make it unreachable.

  • :groups (Array<String>)

    [EC2-VPC] Changes the security groups of the instance. You must specify at least one security group, even if it's just the default security group for the VPC. You must specify the security group ID, not the security group name.

  • :instance_initiated_shutdown_behavior (Types::AttributeValue)

    Specifies whether an instance stops or terminates when you initiate shutdown from the instance (using the operating system command for system shutdown).

  • :instance_type (Types::AttributeValue)

    Changes the instance type to the specified value. For more information, see Instance Types. If the instance type is not valid, the error returned is InvalidInstanceAttributeValue.

  • :kernel (Types::AttributeValue)

    Changes the instance's kernel to the specified value. We recommend that you use PV-GRUB instead of kernels and RAM disks. For more information, see PV-GRUB.

  • :ramdisk (Types::AttributeValue)

    Changes the instance's RAM disk to the specified value. We recommend that you use PV-GRUB instead of kernels and RAM disks. For more information, see PV-GRUB.

  • :sriov_net_support (Types::AttributeValue)

    Set to simple to enable enhanced networking with the Intel 82599 Virtual Function interface for the instance.

    There is no way to disable enhanced networking with the Intel 82599 Virtual Function interface at this time.

    This option is supported only for HVM instances. Specifying this option with a PV instance can make it unreachable.

  • :user_data (Types::BlobAttributeValue)

    Changes the instance's user data to the specified value. If you are using an AWS SDK or command line tool, base64-encoding is performed for you, and you can load the text from a file. Otherwise, you must provide base64-encoded text.

  • :value (String)

    A new value for the attribute. Use only with the kernel, ramdisk, userData, disableApiTermination, or instanceInitiatedShutdownBehavior attribute.

Returns:

  • (EmptyStructure)


876
877
878
879
880
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 876

def modify_attribute(options = {})
  options = options.merge(instance_id: @id)
  resp = @client.modify_instance_attribute(options)
  resp.data
end

#monitor(options = {}) ⇒ Types::MonitorInstancesResult

Examples:

Request syntax with placeholder values


instance.monitor({
  dry_run: false,
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

Returns:



894
895
896
897
898
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 894

def monitor(options = {})
  options = Aws::Util.deep_merge(options, instance_ids: [@id])
  resp = @client.monitor_instances(options)
  resp.data
end

#monitoringTypes::Monitoring

The monitoring for the instance.

Returns:



74
75
76
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 74

def monitoring
  data[:monitoring]
end

#network_interfacesNetworkInterface::Collection



1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1205

def network_interfaces
  batch = []
  data[:network_interfaces].each do |d|
    batch << NetworkInterface.new(
      id: d[:network_interface_id],
      data: d,
      client: @client
    )
  end
  NetworkInterface::Collection.new([batch], size: batch.size)
end

#password_data(options = {}) ⇒ Types::GetPasswordDataResult

Examples:

Request syntax with placeholder values


instance.password_data({
  dry_run: false,
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

Returns:



912
913
914
915
916
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 912

def password_data(options = {})
  options = options.merge(instance_id: @id)
  resp = @client.get_password_data(options)
  resp.data
end

#placementTypes::Placement

The location where the instance launched, if applicable.

Returns:



80
81
82
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 80

def placement
  data[:placement]
end

#placement_groupPlacementGroup?

Returns:



1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1218

def placement_group
  if data[:placement][:group_name]
    PlacementGroup.new(
      name: data[:placement][:group_name],
      client: @client
    )
  else
    nil
  end
end

#platformString

The value is Windows for Windows instances; otherwise blank.

Returns:

  • (String)


86
87
88
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 86

def platform
  data[:platform]
end

#private_dns_nameString

(IPv4 only) The private DNS hostname name assigned to the instance. This DNS hostname can only be used inside the Amazon EC2 network. This name is not available until the instance enters the running state.

[EC2-VPC] The Amazon-provided DNS server resolves Amazon-provided private DNS hostnames if you've enabled DNS resolution and DNS hostnames in your VPC. If you are not using the Amazon-provided DNS server in your VPC, your custom domain name servers must resolve the hostname as appropriate.

Returns:

  • (String)


100
101
102
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 100

def private_dns_name
  data[:private_dns_name]
end

#private_ip_addressString

The private IPv4 address assigned to the instance.

Returns:

  • (String)


106
107
108
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 106

def private_ip_address
  data[:private_ip_address]
end

#product_codesArray<Types::ProductCode>

The product codes attached to this instance, if applicable.

Returns:



112
113
114
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 112

def product_codes
  data[:product_codes]
end

#public_dns_nameString

(IPv4 only) The public DNS name assigned to the instance. This name is not available until the instance enters the running state. For EC2-VPC, this name is only available if you've enabled DNS hostnames for your VPC.

Returns:

  • (String)


121
122
123
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 121

def public_dns_name
  data[:public_dns_name]
end

#public_ip_addressString

The public IPv4 address assigned to the instance, if applicable.

Returns:

  • (String)


127
128
129
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 127

def public_ip_address
  data[:public_ip_address]
end

#ramdisk_idString

The RAM disk associated with this instance, if applicable.

Returns:

  • (String)


133
134
135
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 133

def ramdisk_id
  data[:ramdisk_id]
end

#reboot(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


instance.reboot({
  dry_run: false,
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

Returns:

  • (EmptyStructure)


930
931
932
933
934
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 930

def reboot(options = {})
  options = Aws::Util.deep_merge(options, instance_ids: [@id])
  resp = @client.reboot_instances(options)
  resp.data
end

#report_status(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


instance.report_status({
  description: "String",
  dry_run: false,
  end_time: Time.now,
  reason_codes: ["instance-stuck-in-state"], # required, accepts instance-stuck-in-state, unresponsive, not-accepting-credentials, password-not-available, performance-network, performance-instance-store, performance-ebs-volume, performance-other, other
  start_time: Time.now,
  status: "ok", # required, accepts ok, impaired
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :description (String)

    Descriptive text about the health state of your instance.

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

  • :end_time (Time, DateTime, Date, Integer, String)

    The time at which the reported instance health state ended.

  • :reason_codes (required, Array<String>)

    One or more reason codes that describe the health state of your instance.

    • instance-stuck-in-state: My instance is stuck in a state.

    • unresponsive: My instance is unresponsive.

    • not-accepting-credentials: My instance is not accepting my credentials.

    • password-not-available: A password is not available for my instance.

    • performance-network: My instance is experiencing performance problems that I believe are network related.

    • performance-instance-store: My instance is experiencing performance problems that I believe are related to the instance stores.

    • performance-ebs-volume: My instance is experiencing performance problems that I believe are related to an EBS volume.

    • performance-other: My instance is experiencing performance problems.

    • other: [explain using the description parameter]

  • :start_time (Time, DateTime, Date, Integer, String)

    The time at which the reported instance health state began.

  • :status (required, String)

    The status of all instances listed.

Returns:

  • (EmptyStructure)


989
990
991
992
993
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 989

def report_status(options = {})
  options = Aws::Util.deep_merge(options, instances: [@id])
  resp = @client.report_instance_status(options)
  resp.data
end

#reset_attribute(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


instance.reset_attribute({
  attribute: "instanceType", # required, accepts instanceType, kernel, ramdisk, userData, disableApiTermination, instanceInitiatedShutdownBehavior, rootDeviceName, blockDeviceMapping, productCodes, sourceDestCheck, groupSet, ebsOptimized, sriovNetSupport, enaSupport
  dry_run: false,
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :attribute (required, String)

    The attribute to reset.

    You can only reset the following attributes: kernel | ramdisk | sourceDestCheck. To change an instance attribute, use ModifyInstanceAttribute.

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

Returns:

  • (EmptyStructure)


1014
1015
1016
1017
1018
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1014

def reset_attribute(options = {})
  options = options.merge(instance_id: @id)
  resp = @client.reset_instance_attribute(options)
  resp.data
end

#reset_kernel(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


instance.reset_kernel({
  dry_run: false,
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

Returns:

  • (EmptyStructure)


1032
1033
1034
1035
1036
1037
1038
1039
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1032

def reset_kernel(options = {})
  options = options.merge(
    instance_id: @id,
    attribute: "kernel"
  )
  resp = @client.reset_instance_attribute(options)
  resp.data
end

#reset_ramdisk(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


instance.reset_ramdisk({
  dry_run: false,
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

Returns:

  • (EmptyStructure)


1053
1054
1055
1056
1057
1058
1059
1060
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1053

def reset_ramdisk(options = {})
  options = options.merge(
    instance_id: @id,
    attribute: "ramdisk"
  )
  resp = @client.reset_instance_attribute(options)
  resp.data
end

#reset_source_dest_check(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


instance.reset_source_dest_check({
  dry_run: false,
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

Returns:

  • (EmptyStructure)


1074
1075
1076
1077
1078
1079
1080
1081
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1074

def reset_source_dest_check(options = {})
  options = options.merge(
    instance_id: @id,
    attribute: "sourceDestCheck"
  )
  resp = @client.reset_instance_attribute(options)
  resp.data
end

#root_device_nameString

The root device name (for example, /dev/sda1 or /dev/xvda).

Returns:

  • (String)


223
224
225
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 223

def root_device_name
  data[:root_device_name]
end

#root_device_typeString

The root device type used by the AMI. The AMI can use an EBS volume or an instance store volume.

Returns:

  • (String)


230
231
232
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 230

def root_device_type
  data[:root_device_type]
end

#security_groupsArray<Types::GroupIdentifier>

One or more security groups for the instance.

Returns:



236
237
238
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 236

def security_groups
  data[:security_groups]
end

#source_dest_checkBoolean

Specifies whether to enable an instance launched in a VPC to perform NAT. This controls whether source/destination checking is enabled on the instance. A value of true means that checking is enabled, and false means that checking is disabled. The value must be false for the instance to perform NAT. For more information, see NAT Instances in the Amazon Virtual Private Cloud User Guide.

Returns:

  • (Boolean)


251
252
253
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 251

def source_dest_check
  data[:source_dest_check]
end

#spot_instance_request_idString

If the request is a Spot Instance request, the ID of the request.

Returns:

  • (String)


257
258
259
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 257

def spot_instance_request_id
  data[:spot_instance_request_id]
end

#sriov_net_supportString

Specifies whether enhanced networking with the Intel 82599 Virtual Function interface is enabled.

Returns:

  • (String)


264
265
266
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 264

def sriov_net_support
  data[:sriov_net_support]
end

#start(options = {}) ⇒ Types::StartInstancesResult

Examples:

Request syntax with placeholder values


instance.start({
  additional_info: "String",
  dry_run: false,
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :additional_info (String)

    Reserved.

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

Returns:



1098
1099
1100
1101
1102
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1098

def start(options = {})
  options = Aws::Util.deep_merge(options, instance_ids: [@id])
  resp = @client.start_instances(options)
  resp.data
end

#stateTypes::InstanceState

The current state of the instance.



139
140
141
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 139

def state
  data[:state]
end

#state_reasonTypes::StateReason

The reason for the most recent state transition.

Returns:



270
271
272
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 270

def state_reason
  data[:state_reason]
end

#state_transition_reasonString

The reason for the most recent state transition. This might be an empty string.

Returns:

  • (String)


146
147
148
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 146

def state_transition_reason
  data[:state_transition_reason]
end

#stop(options = {}) ⇒ Types::StopInstancesResult

Examples:

Request syntax with placeholder values


instance.stop({
  dry_run: false,
  force: false,
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

  • :force (Boolean)

    Forces the instances to stop. The instances do not have an opportunity to flush file system caches or file system metadata. If you use this option, you must perform file system check and repair procedures. This option is not recommended for Windows instances.

    Default: false

Returns:



1124
1125
1126
1127
1128
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1124

def stop(options = {})
  options = Aws::Util.deep_merge(options, instance_ids: [@id])
  resp = @client.stop_instances(options)
  resp.data
end

#subnetSubnet?

Returns:



1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1230

def subnet
  if data[:subnet_id]
    Subnet.new(
      id: data[:subnet_id],
      client: @client
    )
  else
    nil
  end
end

#subnet_idString

[EC2-VPC] The ID of the subnet in which the instance is running.

Returns:

  • (String)


152
153
154
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 152

def subnet_id
  data[:subnet_id]
end

#tagsArray<Types::Tag>

Any tags assigned to the instance.

Returns:



276
277
278
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 276

def tags
  data[:tags]
end

#terminate(options = {}) ⇒ Types::TerminateInstancesResult

Examples:

Request syntax with placeholder values


instance.terminate({
  dry_run: false,
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

Returns:



1142
1143
1144
1145
1146
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1142

def terminate(options = {})
  options = Aws::Util.deep_merge(options, instance_ids: [@id])
  resp = @client.terminate_instances(options)
  resp.data
end

#unmonitor(options = {}) ⇒ Types::UnmonitorInstancesResult

Examples:

Request syntax with placeholder values


instance.unmonitor({
  dry_run: false,
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

Returns:



1160
1161
1162
1163
1164
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1160

def unmonitor(options = {})
  options = Aws::Util.deep_merge(options, instance_ids: [@id])
  resp = @client.unmonitor_instances(options)
  resp.data
end

#virtualization_typeString

The virtualization type of the instance.

Returns:

  • (String)


282
283
284
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 282

def virtualization_type
  data[:virtualization_type]
end

#volumes(options = {}) ⇒ Volume::Collection

Examples:

Request syntax with placeholder values


volumes = instance.volumes({
  filters: [
    {
      name: "String",
      values: ["String"],
    },
  ],
  volume_ids: ["String"],
  dry_run: false,
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :filters (Array<Types::Filter>)

    One or more filters.

    • attachment.attach-time - The time stamp when the attachment initiated.

    • attachment.delete-on-termination - Whether the volume is deleted on instance termination.

    • attachment.device - The device name that is exposed to the instance (for example, /dev/sda1).

    • attachment.instance-id - The ID of the instance the volume is attached to.

    • attachment.status - The attachment state (attaching | attached | detaching | detached).

    • availability-zone - The Availability Zone in which the volume was created.

    • create-time - The time stamp when the volume was created.

    • encrypted - The encryption status of the volume.

    • size - The size of the volume, in GiB.

    • snapshot-id - The snapshot from which the volume was created.

    • status - The status of the volume (creating | available | in-use | deleting | deleted | error).

    • tag:key=value - The key/value combination of a tag assigned to the resource. Specify the key of the tag in the filter name and the value of the tag in the filter value. For example, for the tag Purpose=X, specify tag:Purpose for the filter name and X for the filter value.

    • tag-key - The key of a tag assigned to the resource. This filter is independent of the tag-value filter. For example, if you use both the filter "tag-key=Purpose" and the filter "tag-value=X", you get any resources assigned both the tag key Purpose (regardless of what the tag's value is), and the tag value X (regardless of what the tag's key is). If you want to list only resources where Purpose is X, see the tag:key=value filter.

    • tag-value - The value of a tag assigned to the resource. This filter is independent of the tag-key filter.

    • volume-id - The volume ID.

    • volume-type - The Amazon EBS volume type. This can be gp2 for General Purpose SSD, io1 for Provisioned IOPS SSD, st1 for Throughput Optimized HDD, sc1 for Cold HDD, or standard for Magnetic volumes.

  • :volume_ids (Array<String>)

    One or more volume IDs.

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

Returns:



1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1317

def volumes(options = {})
  batches = Enumerator.new do |y|
    options = Aws::Util.deep_merge(options, filters: [{
      name: "attachment.instance-id",
      values: [@id]
    }])
    resp = @client.describe_volumes(options)
    resp.each_page do |page|
      batch = []
      page.data.volumes.each do |v|
        batch << Volume.new(
          id: v.volume_id,
          data: v,
          client: @client
        )
      end
      y.yield(batch)
    end
  end
  Volume::Collection.new(batches)
end

#vpcVpc?

Returns:



1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1340

def vpc
  if data[:vpc_id]
    Vpc.new(
      id: data[:vpc_id],
      client: @client
    )
  else
    nil
  end
end

#vpc_addresses(options = {}) ⇒ VpcAddress::Collection

Examples:

Request syntax with placeholder values


vpc_addresses = instance.vpc_addresses({
  filters: [
    {
      name: "String",
      values: ["String"],
    },
  ],
  public_ips: ["String"],
  allocation_ids: ["String"],
  dry_run: false,
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :filters (Array<Types::Filter>)

    One or more filters. Filter names and values are case-sensitive.

    • allocation-id - [EC2-VPC] The allocation ID for the address.

    • association-id - [EC2-VPC] The association ID for the address.

    • domain - Indicates whether the address is for use in EC2-Classic (standard) or in a VPC (vpc).

    • instance-id - The ID of the instance the address is associated with, if any.

    • network-interface-id - [EC2-VPC] The ID of the network interface that the address is associated with, if any.

    • network-interface-owner-id - The AWS account ID of the owner.

    • private-ip-address - [EC2-VPC] The private IP address associated with the Elastic IP address.

    • public-ip - The Elastic IP address.

  • :public_ips (Array<String>)

    [EC2-Classic] One or more Elastic IP addresses.

    Default: Describes all your Elastic IP addresses.

  • :allocation_ids (Array<String>)

    [EC2-VPC] One or more allocation IDs.

    Default: Describes all your Elastic IP addresses.

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

Returns:



1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1401

def vpc_addresses(options = {})
  batches = Enumerator.new do |y|
    batch = []
    options = Aws::Util.deep_merge(options, filters: [{
      name: "instance-id",
      values: [@id]
    }])
    resp = @client.describe_addresses(options)
    resp.data.addresses.each do |a|
      batch << VpcAddress.new(
        allocation_id: a.allocation_id,
        data: a,
        client: @client
      )
    end
    y.yield(batch)
  end
  VpcAddress::Collection.new(batches)
end

#vpc_idString

[EC2-VPC] The ID of the VPC in which the instance is running.

Returns:

  • (String)


158
159
160
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 158

def vpc_id
  data[:vpc_id]
end

#wait_until(options = {}, &block) ⇒ Resource

Deprecated.

Use [Aws::EC2::Client] #wait_until instead

Note:

The waiting operation is performed on a copy. The original resource remains unchanged

Waiter polls an API operation until a resource enters a desired state.

Basic Usage

Waiter will polls until it is successful, it fails by entering a terminal state, or until a maximum number of attempts are made.

# polls in a loop until condition is true
resource.wait_until(options) {|resource| condition}

Example

instance.wait_until(max_attempts:10, delay:5) {|instance| instance.state.name == 'running' }

Configuration

You can configure the maximum number of polling attempts, and the delay (in seconds) between each polling attempt. The waiting condition is set by passing a block to #wait_until:

# poll for ~25 seconds
resource.wait_until(max_attempts:5,delay:5) {|resource|...}

Callbacks

You can be notified before each polling attempt and before each delay. If you throw :success or :failure from these callbacks, it will terminate the waiter.

started_at = Time.now
# poll for 1 hour, instead of a number of attempts
proc = Proc.new do |attempts, response|
  throw :failure if Time.now - started_at > 3600
end

  # disable max attempts
instance.wait_until(before_wait:proc, max_attempts:nil) {...}

Handling Errors

When a waiter is successful, it returns the Resource. When a waiter fails, it raises an error.

begin
  resource.wait_until(...)
rescue Aws::Waiters::Errors::WaiterFailed
  # resource did not enter the desired state in time
end

attempts attempt in seconds invoked before each attempt invoked before each wait

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :max_attempts (Integer) — default: 10

    Maximum number of

  • :delay (Integer) — default: 10

    Delay between each

  • :before_attempt (Proc) — default: nil

    Callback

  • :before_wait (Proc) — default: nil

    Callback

Returns:

  • (Resource)

    if the waiter was successful

Raises:

  • (Aws::Waiters::Errors::FailureStateError)

    Raised when the waiter terminates because the waiter has entered a state that it will not transition out of, preventing success.

    yet successful.

  • (Aws::Waiters::Errors::UnexpectedError)

    Raised when an error is encountered while polling for a resource that is not expected.

  • (NotImplementedError)

    Raised when the resource does not



485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 485

def wait_until(options = {}, &block)
  self_copy = self.dup
  attempts = 0
  options[:max_attempts] = 10 unless options.key?(:max_attempts)
  options[:delay] ||= 10
  options[:poller] = Proc.new do
    attempts += 1
    if block.call(self_copy)
      [:success, self_copy]
    else
      self_copy.reload unless attempts == options[:max_attempts]
      :retry
    end
  end
  Aws::Waiters::Waiter.new(options).wait({})
end

#wait_until_exists(options = {}) ⇒ Instance

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :max_attempts (Integer) — default: 40
  • :delay (Float) — default: 5
  • :before_attempt (Proc)
  • :before_wait (Proc)

Returns:



341
342
343
344
345
346
347
348
349
350
351
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 341

def wait_until_exists(options = {})
  options, params = separate_params_and_options(options)
  waiter = Waiters::InstanceExists.new(options)
  yield_waiter_and_warn(waiter, &Proc.new) if block_given?
  resp = waiter.wait(params.merge(instance_ids: [@id]))
  Instance.new({
    id: @id,
    data: resp.data.reservations[0].instances[0],
    client: @client
  })
end

#wait_until_running(options = {}) ⇒ Instance

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :max_attempts (Integer) — default: 40
  • :delay (Float) — default: 15
  • :before_attempt (Proc)
  • :before_wait (Proc)

Returns:



359
360
361
362
363
364
365
366
367
368
369
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 359

def wait_until_running(options = {})
  options, params = separate_params_and_options(options)
  waiter = Waiters::InstanceRunning.new(options)
  yield_waiter_and_warn(waiter, &Proc.new) if block_given?
  resp = waiter.wait(params.merge(instance_ids: [@id]))
  Instance.new({
    id: @id,
    data: resp.data.reservations[0].instances[0],
    client: @client
  })
end

#wait_until_stopped(options = {}) ⇒ Instance

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :max_attempts (Integer) — default: 40
  • :delay (Float) — default: 15
  • :before_attempt (Proc)
  • :before_wait (Proc)

Returns:



377
378
379
380
381
382
383
384
385
386
387
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 377

def wait_until_stopped(options = {})
  options, params = separate_params_and_options(options)
  waiter = Waiters::InstanceStopped.new(options)
  yield_waiter_and_warn(waiter, &Proc.new) if block_given?
  resp = waiter.wait(params.merge(instance_ids: [@id]))
  Instance.new({
    id: @id,
    data: resp.data.reservations[0].instances[0],
    client: @client
  })
end

#wait_until_terminated(options = {}) ⇒ Instance

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :max_attempts (Integer) — default: 40
  • :delay (Float) — default: 15
  • :before_attempt (Proc)
  • :before_wait (Proc)

Returns:



395
396
397
398
399
400
401
402
403
404
405
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 395

def wait_until_terminated(options = {})
  options, params = separate_params_and_options(options)
  waiter = Waiters::InstanceTerminated.new(options)
  yield_waiter_and_warn(waiter, &Proc.new) if block_given?
  resp = waiter.wait(params.merge(instance_ids: [@id]))
  Instance.new({
    id: @id,
    data: resp.data.reservations[0].instances[0],
    client: @client
  })
end