Class: Aws::EC2::Image

Inherits:
Object
  • Object
show all
Extended by:
Deprecations
Defined in:
lib/aws-sdk-ec2/image.rb

Defined Under Namespace

Classes: Collection

Read-Only Attributes collapse

Actions collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Image.

Overloads:

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

    Parameters:

    • id (String)

    Options Hash (options):

  • #initialize(options = {}) ⇒ Image

    Options Hash (options):

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


22
23
24
25
26
27
28
# File 'lib/aws-sdk-ec2/image.rb', line 22

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)
  @waiter_block_warned = false
end

Instance Method Details

#architectureString

The architecture of the image.

Returns:

  • (String)


316
317
318
# File 'lib/aws-sdk-ec2/image.rb', line 316

def architecture
  data[:architecture]
end

#block_device_mappingsArray<Types::BlockDeviceMapping>

Any block device mapping entries.

Returns:



72
73
74
# File 'lib/aws-sdk-ec2/image.rb', line 72

def block_device_mappings
  data[:block_device_mappings]
end

#boot_modeString

The boot mode of the image. For more information, see [Boot modes] in the *Amazon EC2 User Guide*.

[1]: docs.aws.amazon.com/AWSEC2/latest/UserGuide/ami-boot.html

Returns:

  • (String)


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

def boot_mode
  data[:boot_mode]
end

#clientClient

Returns:



350
351
352
# File 'lib/aws-sdk-ec2/image.rb', line 350

def client
  @client
end

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

Examples:

Request syntax with placeholder values


tag = image.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>)

    The 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:



541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
# File 'lib/aws-sdk-ec2/image.rb', line 541

def create_tags(options = {})
  batch = []
  options = Aws::Util.deep_merge(options, resources: [@id])
  resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
    @client.create_tags(options)
  end
  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

#creation_dateString

The date and time the image was created.

Returns:

  • (String)


296
297
298
# File 'lib/aws-sdk-ec2/image.rb', line 296

def creation_date
  data[:creation_date]
end

#dataTypes::Image

Returns the data for this Aws::EC2::Image. Calls Client#describe_images if #data_loaded? is ‘false`.

Returns:



372
373
374
375
# File 'lib/aws-sdk-ec2/image.rb', line 372

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.



380
381
382
# File 'lib/aws-sdk-ec2/image.rb', line 380

def data_loaded?
  !!@data
end

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

Examples:

Request syntax with placeholder values


tag = image.delete_tags({
  dry_run: false,
  tags: [
    {
      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 (Array<Types::Tag>)

    The tags to delete. Specify a tag key and an optional tag value to delete specific tags. If you specify a tag key without a tag value, we delete any tag with this key regardless of its value. If you specify a tag key with an empty string as the tag value, we delete the tag only if its value is an empty string.

    If you omit this parameter, we delete all user-defined tags for the specified resources. We do not delete Amazon Web Services-generated tags (tags that have the ‘aws:` prefix).

    Constraints: Up to 1000 tags.

Returns:



588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
# File 'lib/aws-sdk-ec2/image.rb', line 588

def delete_tags(options = {})
  batch = []
  options = Aws::Util.deep_merge(options, resources: [@id])
  resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
    @client.delete_tags(options)
  end
  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

#deprecation_timeString

The date and time to deprecate the AMI, in UTC, in the following format: YYYY-MM-*DD*T*HH*:MM:*SS*Z. If you specified a value for seconds, Amazon EC2 rounds the seconds to the nearest minute.

Returns:

  • (String)


172
173
174
# File 'lib/aws-sdk-ec2/image.rb', line 172

def deprecation_time
  data[:deprecation_time]
end

#deregister(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


image.deregister({
  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)


617
618
619
620
621
622
623
# File 'lib/aws-sdk-ec2/image.rb', line 617

def deregister(options = {})
  options = options.merge(image_id: @id)
  resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
    @client.deregister_image(options)
  end
  resp.data
end

#deregistration_protectionString

Indicates whether deregistration protection is enabled for the AMI.

Returns:

  • (String)


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

def deregistration_protection
  data[:deregistration_protection]
end

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

Examples:

Request syntax with placeholder values


image.describe_attribute({
  attribute: "description", # required, accepts description, kernel, ramdisk, launchPermission, productCodes, blockDeviceMapping, sriovNetSupport, bootMode, tpmSupport, uefiData, lastLaunchedTime, imdsSupport, deregistrationProtection
  dry_run: false,
})

Parameters:

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

    ({})

Options Hash (options):

  • :attribute (required, String)

    The AMI attribute.

    Note: The ‘blockDeviceMapping` attribute is deprecated. Using this attribute returns the `Client.AuthFailure` error. To get information about the block device mappings for an AMI, use the DescribeImages action.

  • :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:



645
646
647
648
649
650
651
# File 'lib/aws-sdk-ec2/image.rb', line 645

def describe_attribute(options = {})
  options = options.merge(image_id: @id)
  resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
    @client.describe_image_attribute(options)
  end
  resp.data
end

#descriptionString

The description of the AMI that was provided during image creation.

Returns:

  • (String)


78
79
80
# File 'lib/aws-sdk-ec2/image.rb', line 78

def description
  data[:description]
end

#ena_supportBoolean

Specifies whether enhanced networking with ENA is enabled.

Returns:

  • (Boolean)


84
85
86
# File 'lib/aws-sdk-ec2/image.rb', line 84

def ena_support
  data[:ena_support]
end

#exists?(options = {}) ⇒ Boolean

Returns ‘true` if the Image exists.

Parameters:

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

    ({})

Returns:

  • (Boolean)

    Returns ‘true` if the Image exists.



387
388
389
390
391
392
393
394
395
396
# File 'lib/aws-sdk-ec2/image.rb', line 387

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 image. Only ‘xen` is supported. `ovm` is not supported.

Returns:

  • (String)


91
92
93
# File 'lib/aws-sdk-ec2/image.rb', line 91

def hypervisor
  data[:hypervisor]
end

#idString Also known as: image_id

Returns:

  • (String)


33
34
35
# File 'lib/aws-sdk-ec2/image.rb', line 33

def id
  @id
end

#identifiersObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Deprecated.


771
772
773
# File 'lib/aws-sdk-ec2/image.rb', line 771

def identifiers
  { id: @id }
end

#image_allowedBoolean

If ‘true`, the AMI satisfies the criteria for Allowed AMIs and can be discovered and used in the account. If `false` and Allowed AMIs is set to `enabled`, the AMI can’t be discovered or used in the account. If ‘false` and Allowed AMIs is set to `audit-mode`, the AMI can be discovered and used in the account.

For more information, see [Control the discovery and use of AMIs in Amazon EC2 with Allowed AMIs] in *Amazon EC2 User Guide*.

[1]: docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-allowed-amis.html

Returns:

  • (Boolean)


238
239
240
# File 'lib/aws-sdk-ec2/image.rb', line 238

def image_allowed
  data[:image_allowed]
end

#image_locationString

The location of the AMI.

Returns:

  • (String)


277
278
279
# File 'lib/aws-sdk-ec2/image.rb', line 277

def image_location
  data[:image_location]
end

#image_owner_aliasString

The owner alias (‘amazon` | `aws-backup-vault` | `aws-marketplace`).

Returns:

  • (String)


97
98
99
# File 'lib/aws-sdk-ec2/image.rb', line 97

def image_owner_alias
  data[:image_owner_alias]
end

#image_typeString

The type of image.

Returns:

  • (String)


322
323
324
# File 'lib/aws-sdk-ec2/image.rb', line 322

def image_type
  data[:image_type]
end

#imds_supportString

If ‘v2.0`, it indicates that IMDSv2 is specified in the AMI. Instances launched from this AMI will have `HttpTokens` automatically set to `required` so that, by default, the instance requires that IMDSv2 is used when requesting instance metadata. In addition, `HttpPutResponseHopLimit` is set to `2`. For more information, see

Configure the AMI][1

in the *Amazon EC2 User Guide*.

[1]: docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-IMDS-new-instances.html#configure-IMDS-new-instances-ami-configuration

Returns:

  • (String)


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

def imds_support
  data[:imds_support]
end

#kernel_idString

The kernel associated with the image, if any. Only applicable for machine images.

Returns:

  • (String)


329
330
331
# File 'lib/aws-sdk-ec2/image.rb', line 329

def kernel_id
  data[:kernel_id]
end

#last_launched_timeString

The date and time, in [ISO 8601 date-time format], when the AMI was last used to launch an EC2 instance. When the AMI is used to launch an instance, there is a 24-hour delay before that usage is reported.

<note markdown=“1”> ‘lastLaunchedTime` data is available starting April 2017.

</note>

[1]: www.iso.org/iso/iso8601

Returns:

  • (String)


221
222
223
# File 'lib/aws-sdk-ec2/image.rb', line 221

def last_launched_time
  data[:last_launched_time]
end

#loadself Also known as: reload

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

image.reload.data

Returns:

  • (self)


360
361
362
363
364
365
366
# File 'lib/aws-sdk-ec2/image.rb', line 360

def load
  resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
    @client.describe_images(image_ids: [@id])
  end
  @data = resp.images[0]
  self
end

#modify_attribute(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


image.modify_attribute({
  attribute: "String",
  description: "value", # value <Hash,Array,String,Numeric,Boolean,IO,Set,nil>
  launch_permission: {
    add: [
      {
        organization_arn: "String",
        organizational_unit_arn: "String",
        user_id: "String",
        group: "all", # accepts all
      },
    ],
    remove: [
      {
        organization_arn: "String",
        organizational_unit_arn: "String",
        user_id: "String",
        group: "all", # accepts all
      },
    ],
  },
  operation_type: "add", # accepts add, remove
  product_codes: ["String"],
  user_groups: ["String"],
  user_ids: ["String"],
  value: "String",
  organization_arns: ["String"],
  organizational_unit_arns: ["String"],
  imds_support: "value", # value <Hash,Array,String,Numeric,Boolean,IO,Set,nil>
  dry_run: false,
})

Parameters:

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

    ({})

Options Hash (options):

  • :attribute (String)

    The name of the attribute to modify.

    Valid values: ‘description` | `imdsSupport` | `launchPermission`

  • :description (Types::AttributeValue)

    A new description for the AMI.

  • :launch_permission (Types::LaunchPermissionModifications)

    A new launch permission for the AMI.

  • :operation_type (String)

    The operation type. This parameter can be used only when the ‘Attribute` parameter is `launchPermission`.

  • :product_codes (Array<String>)

    Not supported.

  • :user_groups (Array<String>)

    The user groups. This parameter can be used only when the ‘Attribute` parameter is `launchPermission`.

  • :user_ids (Array<String>)

    The Amazon Web Services account IDs. This parameter can be used only when the ‘Attribute` parameter is `launchPermission`.

  • :value (String)

    The value of the attribute being modified. This parameter can be used only when the ‘Attribute` parameter is `description` or `imdsSupport`.

  • :organization_arns (Array<String>)

    The Amazon Resource Name (ARN) of an organization. This parameter can be used only when the ‘Attribute` parameter is `launchPermission`.

  • :organizational_unit_arns (Array<String>)

    The Amazon Resource Name (ARN) of an organizational unit (OU). This parameter can be used only when the ‘Attribute` parameter is `launchPermission`.

  • :imds_support (Types::AttributeValue)

    Set to ‘v2.0` to indicate that IMDSv2 is specified in the AMI. Instances launched from this AMI will have `HttpTokens` automatically set to `required` so that, by default, the instance requires that IMDSv2 is used when requesting instance metadata. In addition, `HttpPutResponseHopLimit` is set to `2`. For more information, see

    Configure the AMI][1

    in the *Amazon EC2 User Guide*.

    Do not use this parameter unless your AMI software supports IMDSv2. After you set the value to ‘v2.0`, you can’t undo it. The only way to “reset” your AMI is to create a new AMI from the underlying snapshot.

    [1]: docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-IMDS-new-instances.html#configure-IMDS-new-instances-ami-configuration

  • :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)


737
738
739
740
741
742
743
# File 'lib/aws-sdk-ec2/image.rb', line 737

def modify_attribute(options = {})
  options = options.merge(image_id: @id)
  resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
    @client.modify_image_attribute(options)
  end
  resp.data
end

#nameString

The name of the AMI that was provided during image creation.

Returns:

  • (String)


103
104
105
# File 'lib/aws-sdk-ec2/image.rb', line 103

def name
  data[:name]
end

#owner_idString

The ID of the Amazon Web Services account that owns the image.

Returns:

  • (String)


290
291
292
# File 'lib/aws-sdk-ec2/image.rb', line 290

def owner_id
  data[:owner_id]
end

#platformString

This value is set to ‘windows` for Windows AMIs; otherwise, it is blank.

Returns:

  • (String)


343
344
345
# File 'lib/aws-sdk-ec2/image.rb', line 343

def platform
  data[:platform]
end

#platform_detailsString

The platform details associated with the billing code of the AMI. For more information, see [Understand AMI billing information] in the *Amazon EC2 User Guide*.

[1]: docs.aws.amazon.com/AWSEC2/latest/UserGuide/ami-billing-info.html

Returns:

  • (String)


46
47
48
# File 'lib/aws-sdk-ec2/image.rb', line 46

def platform_details
  data[:platform_details]
end

#product_codesArray<Types::ProductCode>

Any product codes associated with the AMI.

Returns:



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

def product_codes
  data[:product_codes]
end

#publicBoolean

Indicates whether the image has public launch permissions. The value is ‘true` if this image has public launch permissions or `false` if it has only implicit and explicit launch permissions.

Returns:

  • (Boolean)


304
305
306
# File 'lib/aws-sdk-ec2/image.rb', line 304

def public
  data[:public]
end

#ramdisk_idString

The RAM disk associated with the image, if any. Only applicable for machine images.

Returns:

  • (String)


336
337
338
# File 'lib/aws-sdk-ec2/image.rb', line 336

def ramdisk_id
  data[:ramdisk_id]
end

#reset_attribute(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


image.reset_attribute({
  attribute: "launchPermission", # required, accepts launchPermission
  dry_run: false,
})

Parameters:

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

    ({})

Options Hash (options):

  • :attribute (required, String)

    The attribute to reset (currently you can only reset the launch permission attribute).

  • :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)


761
762
763
764
765
766
767
# File 'lib/aws-sdk-ec2/image.rb', line 761

def reset_attribute(options = {})
  options = options.merge(image_id: @id)
  resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
    @client.reset_image_attribute(options)
  end
  resp.data
end

#root_device_nameString

The device name of the root device volume (for example, ‘/dev/sda1`).

Returns:

  • (String)


109
110
111
# File 'lib/aws-sdk-ec2/image.rb', line 109

def root_device_name
  data[:root_device_name]
end

#root_device_typeString

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

Returns:

  • (String)


116
117
118
# File 'lib/aws-sdk-ec2/image.rb', line 116

def root_device_type
  data[:root_device_type]
end

#source_image_idString

The ID of the source AMI from which the AMI was created.

The ID only appears if the AMI was created using CreateImage, CopyImage, or CreateRestoreImageTask. The ID does not appear if the AMI was created using any other API. For some older AMIs, the ID might not be available. For more information, see [Identify the source AMI used to create a new AMI] in the *Amazon EC2 User Guide*.

[1]: docs.aws.amazon.com/AWSEC2/latest/UserGuide/identify-source-ami-used-to-create-new-ami.html

Returns:

  • (String)


254
255
256
# File 'lib/aws-sdk-ec2/image.rb', line 254

def source_image_id
  data[:source_image_id]
end

#source_image_regionString

The Region of the source AMI.

The Region only appears if the AMI was created using CreateImage, CopyImage, or CreateRestoreImageTask. The Region does not appear if the AMI was created using any other API. For some older AMIs, the Region might not be available. For more information, see [Identify the source AMI used to create a new AMI] in the *Amazon EC2 User Guide*.

[1]: docs.aws.amazon.com/AWSEC2/latest/UserGuide/identify-source-ami-used-to-create-new-ami.html

Returns:

  • (String)


271
272
273
# File 'lib/aws-sdk-ec2/image.rb', line 271

def source_image_region
  data[:source_image_region]
end

#source_instance_idString

The ID of the instance that the AMI was created from if the AMI was created using [CreateImage]. This field only appears if the AMI was created using CreateImage.

[1]: docs.aws.amazon.com/AWSEC2/latest/APIReference/API_CreateImage.html

Returns:

  • (String)


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

def source_instance_id
  data[:source_instance_id]
end

#sriov_net_supportString

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

Returns:

  • (String)


123
124
125
# File 'lib/aws-sdk-ec2/image.rb', line 123

def sriov_net_support
  data[:sriov_net_support]
end

#stateString

The current state of the AMI. If the state is ‘available`, the image is successfully registered and can be used to launch an instance.

Returns:

  • (String)


284
285
286
# File 'lib/aws-sdk-ec2/image.rb', line 284

def state
  data[:state]
end

#state_reasonTypes::StateReason

The reason for the state change.

Returns:



129
130
131
# File 'lib/aws-sdk-ec2/image.rb', line 129

def state_reason
  data[:state_reason]
end

#tagsArray<Types::Tag>

Any tags assigned to the image.

Returns:



135
136
137
# File 'lib/aws-sdk-ec2/image.rb', line 135

def tags
  data[:tags]
end

#tpm_supportString

If the image is configured for NitroTPM support, the value is ‘v2.0`. For more information, see [NitroTPM] in the *Amazon EC2 User Guide*.

[1]: docs.aws.amazon.com/AWSEC2/latest/UserGuide/nitrotpm.html

Returns:

  • (String)


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

def tpm_support
  data[:tpm_support]
end

#usage_operationString

The operation of the Amazon EC2 instance and the billing code that is associated with the AMI. ‘usageOperation` corresponds to the

lineitem/Operation][1

column on your Amazon Web Services Cost and

Usage Report and in the [Amazon Web Services Price List API]. You can view these fields on the Instances or AMIs pages in the Amazon EC2 console, or in the responses that are returned by the

DescribeImages][3

command in the Amazon EC2 API, or the

describe-images][4

command in the CLI.

[1]: docs.aws.amazon.com/cur/latest/userguide/Lineitem-columns.html#Lineitem-details-O-Operation [2]: docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/price-changes.html [3]: docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeImages.html [4]: docs.aws.amazon.com/cli/latest/reference/ec2/describe-images.html

Returns:

  • (String)


66
67
68
# File 'lib/aws-sdk-ec2/image.rb', line 66

def usage_operation
  data[:usage_operation]
end

#virtualization_typeString

The type of virtualization of the AMI.

Returns:

  • (String)


141
142
143
# File 'lib/aws-sdk-ec2/image.rb', line 141

def virtualization_type
  data[:virtualization_type]
end

#wait_until(options = {}) {|resource| ... } ⇒ 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) do |instance|
  instance.state.name == 'running'
end

## 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

Yield Parameters:

  • resource (Resource)

    to be used in the waiting condition.

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



498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
# File 'lib/aws-sdk-ec2/image.rb', line 498

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::Plugins::UserAgent.metric('RESOURCE_MODEL') do
    Aws::Waiters::Waiter.new(options).wait({})
  end
end

#wait_until_exists(options = {}, &block) ⇒ Image

Parameters:

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

    ({})

Options Hash (options):

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

Returns:



404
405
406
407
408
409
410
411
412
413
414
415
416
# File 'lib/aws-sdk-ec2/image.rb', line 404

def wait_until_exists(options = {}, &block)
  options, params = separate_params_and_options(options)
  waiter = Waiters::ImageExists.new(options)
  yield_waiter_and_warn(waiter, &block) if block_given?
  resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
    waiter.wait(params.merge(image_ids: [@id]))
  end
  Image.new({
    id: @id,
    data: resp.data.images[0],
    client: @client
  })
end