Class: Aws::EC2::Image
- Inherits:
-
Object
- Object
- Aws::EC2::Image
- Defined in:
- gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb
Defined Under Namespace
Classes: Collection
Read-Only Attributes collapse
-
#architecture ⇒ String
The architecture of the image.
-
#block_device_mappings ⇒ Array<Types::BlockDeviceMapping>
Any block device mapping entries.
-
#boot_mode ⇒ String
The boot mode of the image.
-
#creation_date ⇒ String
The date and time the image was created.
-
#deprecation_time ⇒ String
The date and time to deprecate the AMI, in UTC, in the following format: YYYY-MM-DDTHH:MM:SSZ.
-
#deregistration_protection ⇒ String
Indicates whether deregistration protection is enabled for the AMI.
-
#description ⇒ String
The description of the AMI that was provided during image creation.
-
#ena_support ⇒ Boolean
Specifies whether enhanced networking with ENA is enabled.
-
#free_tier_eligible ⇒ Boolean
Indicates whether the image is eligible for Amazon Web Services Free Tier.
-
#hypervisor ⇒ String
The hypervisor type of the image.
-
#id ⇒ String
(also: #image_id)
-
#image_allowed ⇒ Boolean
If
true, the AMI satisfies the criteria for Allowed AMIs and can be discovered and used in the account. -
#image_location ⇒ String
The location of the AMI.
-
#image_owner_alias ⇒ String
The owner alias (
amazon|aws-backup-vault|aws-marketplace). -
#image_type ⇒ String
The type of image.
-
#image_watermarks ⇒ Array<Types::ImageWatermark>
The watermarks attached to the AMI.
-
#imds_support ⇒ String
If
v2.0, it indicates that IMDSv2 is specified in the AMI. -
#kernel_id ⇒ String
The kernel associated with the image, if any.
-
#last_launched_time ⇒ String
The date and time, in [ISO 8601 date-time format][1], when the AMI was last used to launch an EC2 instance.
-
#name ⇒ String
The name of the AMI that was provided during image creation.
-
#owner_id ⇒ String
The ID of the Amazon Web Services account that owns the image.
-
#platform ⇒ String
This value is set to
windowsfor Windows AMIs; otherwise, it is blank. -
#platform_details ⇒ String
The platform details associated with the billing code of the AMI.
-
#product_codes ⇒ Array<Types::ProductCode>
Any product codes associated with the AMI.
-
#public ⇒ Boolean
Indicates whether the image has public launch permissions.
-
#public_ssm_parameter_name ⇒ String
The name of the public Systems Manager parameter that resolves to this AMI, under the
aws/service/namespace. -
#ramdisk_id ⇒ String
The RAM disk associated with the image, if any.
-
#root_device_name ⇒ String
The device name of the root device volume (for example,
/dev/sda1). -
#root_device_type ⇒ String
The type of root device used by the AMI.
-
#source_image_id ⇒ String
The ID of the source AMI from which the AMI was created.
-
#source_image_region ⇒ String
The Region of the source AMI.
-
#source_instance_id ⇒ String
The ID of the instance that the AMI was created from if the AMI was created using [CreateImage][1].
-
#sriov_net_support ⇒ String
Specifies whether enhanced networking with the Intel 82599 Virtual Function interface is enabled.
-
#state ⇒ String
The current state of the AMI.
-
#state_reason ⇒ Types::StateReason
The reason for the state change.
-
#tags ⇒ Array<Types::Tag>
Any tags assigned to the image.
-
#tpm_support ⇒ String
If the image is configured for NitroTPM support, the value is
v2.0. -
#usage_operation ⇒ String
The operation of the Amazon EC2 instance and the billing code that is associated with the AMI.
-
#virtualization_type ⇒ String
The type of virtualization of the AMI.
Actions collapse
-
#create_tags(options = {}) ⇒ Tag::Collection
-
#delete_tags(options = {}) ⇒ Tag::Collection
-
#deregister(options = {}) ⇒ Types::DeregisterImageResult
-
#describe_attribute(options = {}) ⇒ Types::ImageAttribute
-
#modify_attribute(options = {}) ⇒ EmptyStructure
-
#reset_attribute(options = {}) ⇒ EmptyStructure
Instance Method Summary collapse
-
#client ⇒ Client
-
#data ⇒ Types::Image
Returns the data for this Image.
-
#data_loaded? ⇒ Boolean
Returns
trueif this resource is loaded. -
#exists?(options = {}) ⇒ Boolean
Returns
trueif the Image exists. -
#initialize(*args) ⇒ Image
constructor
A new instance of Image.
- #load ⇒ self (also: #reload)
-
#wait_until(options = {}) {|resource| ... } ⇒ Resource
deprecated
Deprecated.
Use [Aws::EC2::Client] #wait_until instead
-
#wait_until_exists(options = {}, &block) ⇒ Image
Constructor Details
#initialize(id, options = {}) ⇒ Image #initialize(options = {}) ⇒ Image
Returns a new instance of Image.
22 23 24 25 26 27 28 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 22 def initialize(*args) = Hash === args.last ? args.pop.dup : {} @id = extract_id(args, ) @data = .delete(:data) @client = .delete(:client) || Client.new() @waiter_block_warned = false end |
Instance Method Details
#architecture ⇒ String
The architecture of the image.
321 322 323 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 321 def architecture data[:architecture] end |
#block_device_mappings ⇒ Array<Types::BlockDeviceMapping>
Any block device mapping entries.
72 73 74 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 72 def block_device_mappings data[:block_device_mappings] end |
#boot_mode ⇒ String
The boot mode of the image. For more information, see Instance launch behavior with Amazon EC2 boot modes in the Amazon EC2 User Guide.
153 154 155 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 153 def boot_mode data[:boot_mode] end |
#client ⇒ Client
355 356 357 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 355 def client @client end |
#create_tags(options = {}) ⇒ Tag::Collection
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 546 def ( = {}) batch = [] = Aws::Util.deep_merge(, resources: [@id]) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.() end [: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_date ⇒ String
The date and time the image was created.
301 302 303 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 301 def creation_date data[:creation_date] end |
#data ⇒ Types::Image
Returns the data for this Aws::EC2::Image. Calls
Client#describe_images if #data_loaded? is false.
377 378 379 380 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 377 def data load unless @data @data end |
#data_loaded? ⇒ Boolean
385 386 387 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 385 def data_loaded? !!@data end |
#delete_tags(options = {}) ⇒ Tag::Collection
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 593 def ( = {}) batch = [] = Aws::Util.deep_merge(, resources: [@id]) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.() end [: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_time ⇒ String
The date and time to deprecate the AMI, in UTC, in the following format: YYYY-MM-DDTHH:MM:SSZ. If you specified a value for seconds, Amazon EC2 rounds the seconds to the nearest minute.
173 174 175 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 173 def deprecation_time data[:deprecation_time] end |
#deregister(options = {}) ⇒ Types::DeregisterImageResult
633 634 635 636 637 638 639 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 633 def deregister( = {}) = .merge(image_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.deregister_image() end resp.data end |
#deregistration_protection ⇒ String
Indicates whether deregistration protection is enabled for the AMI.
206 207 208 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 206 def deregistration_protection data[:deregistration_protection] end |
#describe_attribute(options = {}) ⇒ Types::ImageAttribute
661 662 663 664 665 666 667 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 661 def describe_attribute( = {}) = .merge(image_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.describe_image_attribute() end resp.data end |
#description ⇒ String
The description of the AMI that was provided during image creation.
78 79 80 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 78 def description data[:description] end |
#ena_support ⇒ Boolean
Specifies whether enhanced networking with ENA is enabled.
84 85 86 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 84 def ena_support data[:ena_support] end |
#exists?(options = {}) ⇒ Boolean
Returns true if the Image exists.
392 393 394 395 396 397 398 399 400 401 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 392 def exists?( = {}) begin wait_until_exists(.merge(max_attempts: 1)) true rescue Aws::Waiters::Errors::UnexpectedError => e raise e.error rescue Aws::Waiters::Errors::WaiterFailed false end end |
#free_tier_eligible ⇒ Boolean
Indicates whether the image is eligible for Amazon Web Services Free Tier.
If
true, the AMI is eligible for Free Tier and can be used to launch instances under the Free Tier limits.If
false, the AMI is not eligible for Free Tier.
263 264 265 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 263 def free_tier_eligible data[:free_tier_eligible] end |
#hypervisor ⇒ String
The hypervisor type of the image. Only xen is supported. ovm is
not supported.
91 92 93 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 91 def hypervisor data[:hypervisor] end |
#id ⇒ String Also known as: image_id
33 34 35 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 33 def id @id end |
#image_allowed ⇒ Boolean
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.
239 240 241 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 239 def image_allowed data[:image_allowed] end |
#image_location ⇒ String
The location of the AMI.
282 283 284 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 282 def image_location data[:image_location] end |
#image_owner_alias ⇒ String
The owner alias (amazon | aws-backup-vault | aws-marketplace).
97 98 99 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 97 def image_owner_alias data[:image_owner_alias] end |
#image_type ⇒ String
The type of image.
327 328 329 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 327 def image_type data[:image_type] end |
#image_watermarks ⇒ Array<Types::ImageWatermark>
The watermarks attached to the AMI.
276 277 278 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 276 def image_watermarks data[:image_watermarks] end |
#imds_support ⇒ String
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 in the Amazon EC2 User Guide.
188 189 190 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 188 def imds_support data[:imds_support] end |
#kernel_id ⇒ String
The kernel associated with the image, if any. Only applicable for machine images.
334 335 336 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 334 def kernel_id data[:kernel_id] end |
#last_launched_time ⇒ String
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.
lastLaunchedTime data is available starting April 2017.
222 223 224 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 222 def last_launched_time data[:last_launched_time] end |
#load ⇒ self 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
365 366 367 368 369 370 371 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 365 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
753 754 755 756 757 758 759 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 753 def modify_attribute( = {}) = .merge(image_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.modify_image_attribute() end resp.data end |
#name ⇒ String
The name of the AMI that was provided during image creation.
103 104 105 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 103 def name data[:name] end |
#owner_id ⇒ String
The ID of the Amazon Web Services account that owns the image.
295 296 297 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 295 def owner_id data[:owner_id] end |
#platform ⇒ String
This value is set to windows for Windows AMIs; otherwise, it is
blank.
348 349 350 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 348 def platform data[:platform] end |
#platform_details ⇒ String
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.
46 47 48 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 46 def platform_details data[:platform_details] end |
#product_codes ⇒ Array<Types::ProductCode>
Any product codes associated with the AMI.
315 316 317 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 315 def product_codes data[:product_codes] end |
#public ⇒ Boolean
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.
309 310 311 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 309 def public data[:public] end |
#public_ssm_parameter_name ⇒ String
The name of the public Systems Manager parameter that resolves to this
AMI, under the aws/service/ namespace.
270 271 272 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 270 def public_ssm_parameter_name data[:public_ssm_parameter_name] end |
#ramdisk_id ⇒ String
The RAM disk associated with the image, if any. Only applicable for machine images.
341 342 343 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 341 def ramdisk_id data[:ramdisk_id] end |
#reset_attribute(options = {}) ⇒ EmptyStructure
777 778 779 780 781 782 783 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 777 def reset_attribute( = {}) = .merge(image_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.reset_image_attribute() end resp.data end |
#root_device_name ⇒ String
The device name of the root device volume (for example, /dev/sda1).
109 110 111 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 109 def root_device_name data[:root_device_name] end |
#root_device_type ⇒ String
The type of root device used by the AMI. The AMI can use an Amazon EBS volume or an instance store volume.
116 117 118 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 116 def root_device_type data[:root_device_type] end |
#source_image_id ⇒ String
The ID of the source AMI from which the AMI was created.
245 246 247 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 245 def source_image_id data[:source_image_id] end |
#source_image_region ⇒ String
The Region of the source AMI.
251 252 253 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 251 def source_image_region data[:source_image_region] end |
#source_instance_id ⇒ String
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.
200 201 202 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 200 def source_instance_id data[:source_instance_id] end |
#sriov_net_support ⇒ String
Specifies whether enhanced networking with the Intel 82599 Virtual Function interface is enabled.
123 124 125 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 123 def sriov_net_support data[:sriov_net_support] end |
#state ⇒ String
The current state of the AMI. If the state is available, the image
is successfully registered and can be used to launch an instance.
289 290 291 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 289 def state data[:state] end |
#state_reason ⇒ Types::StateReason
The reason for the state change.
129 130 131 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 129 def state_reason data[:state_reason] end |
#tags ⇒ Array<Types::Tag>
Any tags assigned to the image.
135 136 137 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 135 def data[:tags] end |
#tpm_support ⇒ String
If the image is configured for NitroTPM support, the value is v2.0.
For more information, see NitroTPM in the Amazon EC2 User
Guide.
165 166 167 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 165 def tpm_support data[:tpm_support] end |
#usage_operation ⇒ String
The operation of the Amazon EC2 instance and the billing code that is
associated with the AMI. usageOperation corresponds to the
lineitem/Operation 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 command in the Amazon EC2 API, or the
describe-images command in the CLI.
66 67 68 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 66 def usage_operation data[:usage_operation] end |
#virtualization_type ⇒ String
The type of virtualization of the AMI.
141 142 143 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 141 def virtualization_type data[:virtualization_type] end |
#wait_until(options = {}) {|resource| ... } ⇒ Resource
Use [Aws::EC2::Client] #wait_until instead
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() {|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
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 503 def wait_until( = {}, &block) self_copy = self.dup attempts = 0 [:max_attempts] = 10 unless .key?(:max_attempts) [:delay] ||= 10 [:poller] = Proc.new do attempts += 1 if block.call(self_copy) [:success, self_copy] else self_copy.reload unless attempts == [:max_attempts] :retry end end Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do Aws::Waiters::Waiter.new().wait({}) end end |
#wait_until_exists(options = {}, &block) ⇒ Image
409 410 411 412 413 414 415 416 417 418 419 420 421 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/image.rb', line 409 def wait_until_exists( = {}, &block) , params = () waiter = Waiters::ImageExists.new() 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 |