Class: Aws::EC2::Instance
- Inherits:
-
Object
- Object
- Aws::EC2::Instance
- Defined in:
- gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb,
gems/aws-sdk-ec2/lib/aws-sdk-ec2/customizations/instance.rb
Defined Under Namespace
Classes: Collection
Read-Only Attributes collapse
-
#ami_launch_index ⇒ Integer
The AMI launch index, which can be used to find this instance in the launch group.
-
#architecture ⇒ String
The architecture of the image.
-
#block_device_mappings ⇒ Array<Types::InstanceBlockDeviceMapping>
Any block device mapping entries for the instance.
-
#boot_mode ⇒ String
The boot mode that was specified by the AMI.
-
#capacity_block_id ⇒ String
The ID of the Capacity Block.
-
#capacity_reservation_id ⇒ String
The ID of the Capacity Reservation.
-
#capacity_reservation_specification ⇒ Types::CapacityReservationSpecificationResponse
Information about the Capacity Reservation targeting option.
-
#client_token ⇒ String
The idempotency token you provided when you launched the instance, if applicable.
-
#cpu_options ⇒ Types::CpuOptions
The CPU options for the instance.
-
#current_instance_boot_mode ⇒ String
The boot mode that is used to boot the instance at launch or start.
-
#ebs_optimized ⇒ Boolean
Indicates whether the instance is optimized for Amazon EBS I/O.
-
#elastic_gpu_associations ⇒ Array<Types::ElasticGpuAssociation>
Deprecated.
-
#elastic_inference_accelerator_associations ⇒ Array<Types::ElasticInferenceAcceleratorAssociation>
Deprecated.
-
#ena_support ⇒ Boolean
Specifies whether enhanced networking with ENA is enabled.
-
#enclave_options ⇒ Types::EnclaveOptions
Indicates whether the instance is enabled for Amazon Web Services Nitro Enclaves.
-
#hibernation_options ⇒ Types::HibernationOptions
Indicates whether the instance is enabled for hibernation.
-
#hypervisor ⇒ String
The hypervisor type of the instance.
-
#iam_instance_profile ⇒ Types::IamInstanceProfile
The IAM instance profile associated with the instance, if applicable.
-
#id ⇒ String
(also: #instance_id)
-
#image_id ⇒ String
The ID of the AMI used to launch the instance.
-
#instance_lifecycle ⇒ String
Indicates whether this is a Spot Instance or a Scheduled Instance.
-
#instance_type ⇒ String
The instance type.
-
#ipv_6_address ⇒ String
The IPv6 address assigned to the instance.
-
#kernel_id ⇒ String
The kernel associated with this instance, if applicable.
-
#key_name ⇒ String
The name of the key pair, if this instance was launched with an associated key pair.
-
#launch_time ⇒ Time
The time that the instance was last launched.
-
#licenses ⇒ Array<Types::LicenseConfiguration>
The license configurations for the instance.
-
#maintenance_options ⇒ Types::InstanceMaintenanceOptions
Provides information on the recovery and maintenance options of your instance.
-
#metadata_options ⇒ Types::InstanceMetadataOptionsResponse
The metadata options for the instance.
-
#monitoring ⇒ Types::Monitoring
The monitoring for the instance.
-
#network_performance_options ⇒ Types::InstanceNetworkPerformanceOptions
Contains settings for the network performance options for your instance.
-
#operator ⇒ Types::OperatorResponse
The service provider that manages the instance.
-
#outpost_arn ⇒ String
The Amazon Resource Name (ARN) of the Outpost.
-
#placement ⇒ Types::Placement
The location where the instance launched, if applicable.
-
#platform ⇒ String
The platform.
-
#platform_details ⇒ String
The platform details value for the instance.
-
#private_dns_name ⇒ String
[IPv4 only] The private DNS hostname name assigned to the instance.
-
#private_dns_name_options ⇒ Types::PrivateDnsNameOptionsResponse
The options for the instance hostname.
-
#private_ip_address ⇒ String
The private IPv4 address assigned to the instance.
-
#product_codes ⇒ Array<Types::ProductCode>
The product codes attached to this instance, if applicable.
-
#public_dns_name ⇒ String
The public DNS name assigned to the instance.
-
#public_ip_address ⇒ String
The public IPv4 address, or the Carrier IP address assigned to the instance, if applicable.
-
#ramdisk_id ⇒ String
The RAM disk associated with this instance, if applicable.
-
#root_device_name ⇒ String
The device name of the root device volume (for example,
/dev/sda1). -
#root_device_type ⇒ String
The root device type used by the AMI.
-
#secondary_interfaces ⇒ Array<Types::InstanceSecondaryInterface>
The secondary interfaces for the instance.
-
#security_groups ⇒ Array<Types::GroupIdentifier>
The security groups for the instance.
-
#source_dest_check ⇒ Boolean
Indicates whether source/destination checking is enabled.
-
#spot_instance_request_id ⇒ String
If the request is a Spot Instance request, the ID of the request.
-
#sriov_net_support ⇒ String
Specifies whether enhanced networking with the Intel 82599 Virtual Function interface is enabled.
-
#state ⇒ Types::InstanceState
The current state of the instance.
-
#state_reason ⇒ Types::StateReason
The reason for the most recent state transition.
-
#state_transition_reason ⇒ String
The reason for the most recent state transition.
-
#subnet_id ⇒ String
The ID of the subnet in which the instance is running.
-
#tags ⇒ Array<Types::Tag>
Any tags assigned to the instance.
-
#tpm_support ⇒ String
If the instance is configured for NitroTPM support, the value is
v2.0. -
#usage_operation ⇒ String
The usage operation value for the instance.
-
#usage_operation_update_time ⇒ Time
The time that the usage operation was last updated.
-
#virtualization_type ⇒ String
The virtualization type of the instance.
-
#vpc_id ⇒ String
The ID of the VPC in which the instance is running.
Actions collapse
-
#attach_classic_link_vpc(options = {}) ⇒ Types::AttachClassicLinkVpcResult
-
#attach_volume(options = {}) ⇒ Types::VolumeAttachment
-
#console_output(options = {}) ⇒ Types::GetConsoleOutputResult
-
#create_image(options = {}) ⇒ Image
-
#create_tags(options = {}) ⇒ Tag::Collection
-
#delete_tags(options = {}) ⇒ Tag::Collection
-
#describe_attribute(options = {}) ⇒ Types::InstanceAttribute
-
#detach_classic_link_vpc(options = {}) ⇒ Types::DetachClassicLinkVpcResult
-
#detach_volume(options = {}) ⇒ Types::VolumeAttachment
-
#modify_attribute(options = {}) ⇒ EmptyStructure
-
#monitor(options = {}) ⇒ Types::MonitorInstancesResult
-
#password_data(options = {}) ⇒ Types::GetPasswordDataResult
-
#reboot(options = {}) ⇒ EmptyStructure
-
#report_status(options = {}) ⇒ EmptyStructure
-
#reset_attribute(options = {}) ⇒ EmptyStructure
-
#reset_kernel(options = {}) ⇒ EmptyStructure
-
#reset_ramdisk(options = {}) ⇒ EmptyStructure
-
#reset_source_dest_check(options = {}) ⇒ EmptyStructure
-
#start(options = {}) ⇒ Types::StartInstancesResult
-
#stop(options = {}) ⇒ Types::StopInstancesResult
-
#terminate(options = {}) ⇒ Types::TerminateInstancesResult
-
#unmonitor(options = {}) ⇒ Types::UnmonitorInstancesResult
Associations collapse
-
#classic_address ⇒ ClassicAddress?
-
#image ⇒ Image?
-
#key_pair ⇒ KeyPairInfo?
-
#network_interfaces ⇒ NetworkInterface::Collection
-
#placement_group ⇒ PlacementGroup?
-
#subnet ⇒ Subnet?
-
#volumes(options = {}) ⇒ Volume::Collection
-
#vpc ⇒ Vpc?
-
#vpc_addresses(options = {}) ⇒ VpcAddress::Collection
Instance Method Summary collapse
-
#client ⇒ Client
-
#data ⇒ Types::Instance
Returns the data for this Instance.
-
#data_loaded? ⇒ Boolean
Returns
trueif this resource is loaded. -
#decrypt_windows_password(key_pair_path) ⇒ String
-
#exists?(options = {}) ⇒ Boolean
Returns
trueif the Instance exists. -
#initialize(*args) ⇒ Instance
constructor
A new instance of Instance.
- #load ⇒ self (also: #reload)
-
#wait_until(options = {}) {|resource| ... } ⇒ Resource
deprecated
Deprecated.
Use [Aws::EC2::Client] #wait_until instead
-
#wait_until_exists(options = {}, &block) ⇒ Instance
-
#wait_until_running(options = {}, &block) ⇒ Instance
-
#wait_until_stopped(options = {}, &block) ⇒ Instance
-
#wait_until_terminated(options = {}, &block) ⇒ Instance
Constructor Details
#initialize(id, options = {}) ⇒ Instance #initialize(options = {}) ⇒ Instance
Returns a new instance of Instance.
22 23 24 25 26 27 28 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.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
#ami_launch_index ⇒ Integer
The AMI launch index, which can be used to find this instance in the launch group.
395 396 397 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 395 def ami_launch_index data[:ami_launch_index] end |
#architecture ⇒ String
The architecture of the image.
40 41 42 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 40 def architecture data[:architecture] end |
#attach_classic_link_vpc(options = {}) ⇒ Types::AttachClassicLinkVpcResult
729 730 731 732 733 734 735 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 729 def attach_classic_link_vpc( = {}) = .merge(instance_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.attach_classic_link_vpc() end resp.data end |
#attach_volume(options = {}) ⇒ Types::VolumeAttachment
760 761 762 763 764 765 766 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 760 def attach_volume( = {}) = .merge(instance_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.attach_volume() end resp.data end |
#block_device_mappings ⇒ Array<Types::InstanceBlockDeviceMapping>
Any block device mapping entries for the instance.
46 47 48 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 46 def block_device_mappings data[:block_device_mappings] end |
#boot_mode ⇒ String
The boot mode that was specified by the AMI. If the value is
uefi-preferred, the AMI supports both UEFI and Legacy BIOS. The
currentInstanceBootMode parameter is the boot mode that is used to
boot the instance at launch or start.
For more information, see Boot modes in the Amazon EC2 User Guide.
245 246 247 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 245 def boot_mode data[:boot_mode] end |
#capacity_block_id ⇒ String
The ID of the Capacity Block.
187 188 189 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 187 def capacity_block_id data[:capacity_block_id] end |
#capacity_reservation_id ⇒ String
The ID of the Capacity Reservation.
193 194 195 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 193 def capacity_reservation_id data[:capacity_reservation_id] end |
#capacity_reservation_specification ⇒ Types::CapacityReservationSpecificationResponse
Information about the Capacity Reservation targeting option.
199 200 201 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 199 def capacity_reservation_specification data[:capacity_reservation_specification] end |
#classic_address ⇒ ClassicAddress?
1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1671 def classic_address if data[:public_ip_address] ClassicAddress.new( public_ip: data[:public_ip_address], client: @client ) else nil end end |
#client ⇒ Client
481 482 483 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 481 def client @client end |
#client_token ⇒ String
The idempotency token you provided when you launched the instance, if applicable.
53 54 55 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 53 def client_token data[:client_token] end |
#console_output(options = {}) ⇒ Types::GetConsoleOutputResult
785 786 787 788 789 790 791 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 785 def console_output( = {}) = .merge(instance_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.get_console_output() end resp.data end |
#cpu_options ⇒ Types::CpuOptions
The CPU options for the instance.
176 177 178 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 176 def data[:cpu_options] end |
#create_image(options = {}) ⇒ Image
948 949 950 951 952 953 954 955 956 957 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 948 def create_image( = {}) = .merge(instance_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.create_image() end Image.new( id: resp.data.image_id, client: @client ) end |
#create_tags(options = {}) ⇒ Tag::Collection
981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 981 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 |
#current_instance_boot_mode ⇒ String
The boot mode that is used to boot the instance at launch or start. For more information, see Boot modes in the Amazon EC2 User Guide.
316 317 318 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 316 def current_instance_boot_mode data[:current_instance_boot_mode] end |
#data ⇒ Types::Instance
Returns the data for this Aws::EC2::Instance. Calls
Client#describe_instances if #data_loaded? is false.
503 504 505 506 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 503 def data load unless @data @data end |
#data_loaded? ⇒ Boolean
511 512 513 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 511 def data_loaded? !!@data end |
#decrypt_windows_password(key_pair_path) ⇒ String
11 12 13 14 15 16 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/customizations/instance.rb', line 11 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 |
#delete_tags(options = {}) ⇒ Tag::Collection
1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1028 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 |
#describe_attribute(options = {}) ⇒ Types::InstanceAttribute
1062 1063 1064 1065 1066 1067 1068 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1062 def describe_attribute( = {}) = .merge(instance_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.describe_instance_attribute() end resp.data end |
#detach_classic_link_vpc(options = {}) ⇒ Types::DetachClassicLinkVpcResult
1085 1086 1087 1088 1089 1090 1091 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1085 def detach_classic_link_vpc( = {}) = .merge(instance_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.detach_classic_link_vpc() end resp.data end |
#detach_volume(options = {}) ⇒ Types::VolumeAttachment
1121 1122 1123 1124 1125 1126 1127 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1121 def detach_volume( = {}) = .merge(instance_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.detach_volume() end resp.data end |
#ebs_optimized ⇒ Boolean
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.
63 64 65 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 63 def ebs_optimized data[:ebs_optimized] end |
#elastic_gpu_associations ⇒ Array<Types::ElasticGpuAssociation>
Deprecated.
98 99 100 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 98 def elastic_gpu_associations data[:elastic_gpu_associations] end |
#elastic_inference_accelerator_associations ⇒ Array<Types::ElasticInferenceAcceleratorAssociation>
Deprecated
108 109 110 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 108 def elastic_inference_accelerator_associations data[:elastic_inference_accelerator_associations] end |
#ena_support ⇒ Boolean
Specifies whether enhanced networking with ENA is enabled.
69 70 71 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 69 def ena_support data[:ena_support] end |
#enclave_options ⇒ Types::EnclaveOptions
Indicates whether the instance is enabled for Amazon Web Services Nitro Enclaves.
224 225 226 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 224 def data[:enclave_options] end |
#exists?(options = {}) ⇒ Boolean
Returns true if the Instance exists.
518 519 520 521 522 523 524 525 526 527 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 518 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 |
#hibernation_options ⇒ Types::HibernationOptions
Indicates whether the instance is enabled for hibernation.
205 206 207 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 205 def data[:hibernation_options] end |
#hypervisor ⇒ String
The hypervisor type of the instance. The value xen is used for both
Xen and Nitro hypervisors.
76 77 78 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 76 def hypervisor data[:hypervisor] end |
#iam_instance_profile ⇒ Types::IamInstanceProfile
The IAM instance profile associated with the instance, if applicable.
82 83 84 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 82 def iam_instance_profile data[:iam_instance_profile] end |
#id ⇒ String Also known as: instance_id
33 34 35 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 33 def id @id end |
#image ⇒ Image?
1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1683 def image if data[:image_id] Image.new( id: data[:image_id], client: @client ) else nil end end |
#image_id ⇒ String
The ID of the AMI used to launch the instance.
341 342 343 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 341 def image_id data[:image_id] end |
#instance_lifecycle ⇒ String
Indicates whether this is a Spot Instance or a Scheduled Instance.
88 89 90 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 88 def instance_lifecycle data[:instance_lifecycle] end |
#instance_type ⇒ String
The instance type.
407 408 409 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 407 def instance_type data[:instance_type] end |
#ipv_6_address ⇒ String
The IPv6 address assigned to the instance.
285 286 287 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 285 def ipv_6_address data[:ipv_6_address] end |
#kernel_id ⇒ String
The kernel associated with this instance, if applicable.
427 428 429 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 427 def kernel_id data[:kernel_id] end |
#key_name ⇒ String
The name of the key pair, if this instance was launched with an associated key pair.
388 389 390 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 388 def key_name data[:key_name] end |
#key_pair ⇒ KeyPairInfo?
1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1695 def key_pair if data[:key_name] KeyPairInfo.new( name: data[:key_name], client: @client ) else nil end end |
#launch_time ⇒ Time
The time that the instance was last launched. To determine the time that instance was first launched, see the attachment time for the primary network interface.
415 416 417 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 415 def launch_time data[:launch_time] end |
#licenses ⇒ Array<Types::LicenseConfiguration>
The license configurations for the instance.
211 212 213 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 211 def licenses data[:licenses] end |
#load ⇒ self 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
491 492 493 494 495 496 497 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 491 def load resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.describe_instances(instance_ids: [@id]) end @data = resp.reservations[0].instances[0] self end |
#maintenance_options ⇒ Types::InstanceMaintenanceOptions
Provides information on the recovery and maintenance options of your instance.
304 305 306 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 304 def data[:maintenance_options] end |
#metadata_options ⇒ Types::InstanceMetadataOptionsResponse
The metadata options for the instance.
217 218 219 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 217 def data[:metadata_options] end |
#modify_attribute(options = {}) ⇒ EmptyStructure
1309 1310 1311 1312 1313 1314 1315 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1309 def modify_attribute( = {}) = .merge(instance_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.modify_instance_attribute() end resp.data end |
#monitor(options = {}) ⇒ Types::MonitorInstancesResult
1329 1330 1331 1332 1333 1334 1335 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1329 def monitor( = {}) = Aws::Util.deep_merge(, instance_ids: [@id]) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.monitor_instances() end resp.data end |
#monitoring ⇒ Types::Monitoring
The monitoring for the instance.
446 447 448 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 446 def monitoring data[:monitoring] end |
#network_interfaces ⇒ NetworkInterface::Collection
1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1707 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 |
#network_performance_options ⇒ Types::InstanceNetworkPerformanceOptions
Contains settings for the network performance options for your instance.
323 324 325 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 323 def data[:network_performance_options] end |
#operator ⇒ Types::OperatorResponse
The service provider that manages the instance.
329 330 331 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 329 def operator data[:operator] end |
#outpost_arn ⇒ String
The Amazon Resource Name (ARN) of the Outpost.
114 115 116 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 114 def outpost_arn data[:outpost_arn] end |
#password_data(options = {}) ⇒ Types::GetPasswordDataResult
1349 1350 1351 1352 1353 1354 1355 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1349 def password_data( = {}) = .merge(instance_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.get_password_data() end resp.data end |
#placement ⇒ Types::Placement
The location where the instance launched, if applicable.
421 422 423 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 421 def placement data[:placement] end |
#placement_group ⇒ PlacementGroup?
1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1720 def placement_group if data[:placement][:group_name] PlacementGroup.new( name: data[:placement][:group_name], client: @client ) else nil end end |
#platform ⇒ String
The platform. This value is windows for Windows instances;
otherwise, it is empty.
440 441 442 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 440 def platform data[:platform] end |
#platform_details ⇒ String
The platform details value for the instance. For more information, see AMI billing information fields in the Amazon EC2 User Guide.
256 257 258 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 256 def platform_details data[:platform_details] end |
#private_dns_name ⇒ String
[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.
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.
361 362 363 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 361 def private_dns_name data[:private_dns_name] end |
#private_dns_name_options ⇒ Types::PrivateDnsNameOptionsResponse
The options for the instance hostname.
279 280 281 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 279 def data[:private_dns_name_options] end |
#private_ip_address ⇒ String
The private IPv4 address assigned to the instance.
464 465 466 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 464 def private_ip_address data[:private_ip_address] end |
#product_codes ⇒ Array<Types::ProductCode>
The product codes attached to this instance, if applicable.
401 402 403 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 401 def product_codes data[:product_codes] end |
#public_dns_name ⇒ String
The public DNS name assigned to the instance. This name is not
available until the instance enters the running state. This name is
only available if you've enabled DNS hostnames for your VPC. The
format of this name depends on the public hostname type.
374 375 376 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 374 def public_dns_name data[:public_dns_name] end |
#public_ip_address ⇒ String
The public IPv4 address, or the Carrier IP address assigned to the instance, if applicable.
A Carrier IP address only applies to an instance launched in a subnet associated with a Wavelength Zone.
474 475 476 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 474 def public_ip_address data[:public_ip_address] end |
#ramdisk_id ⇒ String
The RAM disk associated with this instance, if applicable.
433 434 435 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 433 def ramdisk_id data[:ramdisk_id] end |
#reboot(options = {}) ⇒ EmptyStructure
1369 1370 1371 1372 1373 1374 1375 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1369 def reboot( = {}) = Aws::Util.deep_merge(, instance_ids: [@id]) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.reboot_instances() end resp.data end |
#report_status(options = {}) ⇒ EmptyStructure
1429 1430 1431 1432 1433 1434 1435 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1429 def report_status( = {}) = Aws::Util.deep_merge(, instances: [@id]) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.report_instance_status() end resp.data end |
#reset_attribute(options = {}) ⇒ EmptyStructure
1455 1456 1457 1458 1459 1460 1461 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1455 def reset_attribute( = {}) = .merge(instance_id: @id) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.reset_instance_attribute() end resp.data end |
#reset_kernel(options = {}) ⇒ EmptyStructure
1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1475 def reset_kernel( = {}) = .merge( instance_id: @id, attribute: "kernel" ) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.reset_instance_attribute() end resp.data end |
#reset_ramdisk(options = {}) ⇒ EmptyStructure
1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1498 def reset_ramdisk( = {}) = .merge( instance_id: @id, attribute: "ramdisk" ) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.reset_instance_attribute() end resp.data end |
#reset_source_dest_check(options = {}) ⇒ EmptyStructure
1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1521 def reset_source_dest_check( = {}) = .merge( instance_id: @id, attribute: "sourceDestCheck" ) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.reset_instance_attribute() end resp.data end |
#root_device_name ⇒ String
The device name of the root device volume (for example, /dev/sda1).
120 121 122 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 120 def root_device_name data[:root_device_name] end |
#root_device_type ⇒ String
The root device type used by the AMI. The AMI can use an EBS volume or an instance store volume.
127 128 129 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 127 def root_device_type data[:root_device_type] end |
#secondary_interfaces ⇒ Array<Types::InstanceSecondaryInterface>
The secondary interfaces for the instance.
335 336 337 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 335 def secondary_interfaces data[:secondary_interfaces] end |
#security_groups ⇒ Array<Types::GroupIdentifier>
The security groups for the instance.
133 134 135 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 133 def security_groups data[:security_groups] end |
#source_dest_check ⇒ Boolean
Indicates whether source/destination checking is enabled.
139 140 141 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 139 def source_dest_check data[:source_dest_check] end |
#spot_instance_request_id ⇒ String
If the request is a Spot Instance request, the ID of the request.
145 146 147 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 145 def spot_instance_request_id data[:spot_instance_request_id] end |
#sriov_net_support ⇒ String
Specifies whether enhanced networking with the Intel 82599 Virtual Function interface is enabled.
152 153 154 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 152 def sriov_net_support data[:sriov_net_support] end |
#start(options = {}) ⇒ Types::StartInstancesResult
1547 1548 1549 1550 1551 1552 1553 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1547 def start( = {}) = Aws::Util.deep_merge(, instance_ids: [@id]) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.start_instances() end resp.data end |
#state ⇒ Types::InstanceState
The current state of the instance.
347 348 349 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 347 def state data[:state] end |
#state_reason ⇒ Types::StateReason
The reason for the most recent state transition.
158 159 160 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 158 def state_reason data[:state_reason] end |
#state_transition_reason ⇒ String
The reason for the most recent state transition. This might be an empty string.
381 382 383 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 381 def state_transition_reason data[:state_transition_reason] end |
#stop(options = {}) ⇒ Types::StopInstancesResult
1607 1608 1609 1610 1611 1612 1613 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1607 def stop( = {}) = Aws::Util.deep_merge(, instance_ids: [@id]) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.stop_instances() end resp.data end |
#subnet ⇒ Subnet?
1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1732 def subnet if data[:subnet_id] Subnet.new( id: data[:subnet_id], client: @client ) else nil end end |
#subnet_id ⇒ String
The ID of the subnet in which the instance is running.
452 453 454 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 452 def subnet_id data[:subnet_id] end |
#tags ⇒ Array<Types::Tag>
Any tags assigned to the instance.
164 165 166 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 164 def data[:tags] end |
#terminate(options = {}) ⇒ Types::TerminateInstancesResult
1640 1641 1642 1643 1644 1645 1646 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1640 def terminate( = {}) = Aws::Util.deep_merge(, instance_ids: [@id]) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.terminate_instances() end resp.data end |
#tpm_support ⇒ String
If the instance is configured for NitroTPM support, the value is
v2.0. For more information, see NitroTPM in the Amazon EC2
User Guide.
297 298 299 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 297 def tpm_support data[:tpm_support] end |
#unmonitor(options = {}) ⇒ Types::UnmonitorInstancesResult
1660 1661 1662 1663 1664 1665 1666 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1660 def unmonitor( = {}) = Aws::Util.deep_merge(, instance_ids: [@id]) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.unmonitor_instances() end resp.data end |
#usage_operation ⇒ String
The usage operation value for the instance. For more information, see AMI billing information fields in the Amazon EC2 User Guide.
267 268 269 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 267 def usage_operation data[:usage_operation] end |
#usage_operation_update_time ⇒ Time
The time that the usage operation was last updated.
273 274 275 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 273 def usage_operation_update_time data[:usage_operation_update_time] end |
#virtualization_type ⇒ String
The virtualization type of the instance.
170 171 172 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 170 def virtualization_type data[:virtualization_type] end |
#volumes(options = {}) ⇒ Volume::Collection
1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1834 def volumes( = {}) batches = Enumerator.new do |y| = Aws::Util.deep_merge(, filters: [{ name: "attachment.instance-id", values: [@id] }]) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.describe_volumes() end 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 |
#vpc ⇒ Vpc?
1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1859 def vpc if data[:vpc_id] Vpc.new( id: data[:vpc_id], client: @client ) else nil end end |
#vpc_addresses(options = {}) ⇒ VpcAddress::Collection
1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1930 def vpc_addresses( = {}) batches = Enumerator.new do |y| batch = [] = Aws::Util.deep_merge(, filters: [{ name: "instance-id", values: [@id] }]) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.describe_addresses() end 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_id ⇒ String
The ID of the VPC in which the instance is running.
458 459 460 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 458 def vpc_id data[:vpc_id] 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
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 689 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) ⇒ Instance
535 536 537 538 539 540 541 542 543 544 545 546 547 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 535 def wait_until_exists( = {}, &block) , params = () waiter = Waiters::InstanceExists.new() yield_waiter_and_warn(waiter, &block) if block_given? resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do waiter.wait(params.merge(instance_ids: [@id])) end Instance.new({ id: @id, data: resp.data.reservations[0].instances[0], client: @client }) end |
#wait_until_running(options = {}, &block) ⇒ Instance
555 556 557 558 559 560 561 562 563 564 565 566 567 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 555 def wait_until_running( = {}, &block) , params = () waiter = Waiters::InstanceRunning.new() yield_waiter_and_warn(waiter, &block) if block_given? resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do waiter.wait(params.merge(instance_ids: [@id])) end Instance.new({ id: @id, data: resp.data.reservations[0].instances[0], client: @client }) end |
#wait_until_stopped(options = {}, &block) ⇒ Instance
575 576 577 578 579 580 581 582 583 584 585 586 587 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 575 def wait_until_stopped( = {}, &block) , params = () waiter = Waiters::InstanceStopped.new() yield_waiter_and_warn(waiter, &block) if block_given? resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do waiter.wait(params.merge(instance_ids: [@id])) end Instance.new({ id: @id, data: resp.data.reservations[0].instances[0], client: @client }) end |
#wait_until_terminated(options = {}, &block) ⇒ Instance
595 596 597 598 599 600 601 602 603 604 605 606 607 |
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 595 def wait_until_terminated( = {}, &block) , params = () waiter = Waiters::InstanceTerminated.new() yield_waiter_and_warn(waiter, &block) if block_given? resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do waiter.wait(params.merge(instance_ids: [@id])) end Instance.new({ id: @id, data: resp.data.reservations[0].instances[0], client: @client }) end |