Class: Aws::EC2::Instance
- Inherits:
-
Object
- Object
- Aws::EC2::Instance
- Extended by:
- Deprecations
- Defined in:
- lib/aws-sdk-ec2/customizations/instance.rb,
lib/aws-sdk-ec2/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.
-
#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.
-
#ebs_optimized ⇒ Boolean
Indicates whether the instance is optimized for Amazon EBS I/O.
-
#elastic_gpu_associations ⇒ Array<Types::ElasticGpuAssociation>
The Elastic GPU associated with the instance.
-
#elastic_inference_accelerator_associations ⇒ Array<Types::ElasticInferenceAcceleratorAssociation>
The elastic inference accelerator associated with the instance.
-
#ena_support ⇒ Boolean
Specifies whether enhanced networking with ENA is enabled.
-
#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.
-
#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 the instance was launched.
-
#licenses ⇒ Array<Types::LicenseConfiguration>
The license configurations.
-
#monitoring ⇒ Types::Monitoring
The monitoring for the instance.
-
#placement ⇒ Types::Placement
The location where the instance launched, if applicable.
-
#platform ⇒ String
The value is ‘Windows` for Windows instances; otherwise blank.
-
#private_dns_name ⇒ String
(IPv4 only) The private DNS hostname name assigned to the instance.
-
#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
(IPv4 only) The public DNS name assigned to the instance.
-
#public_ip_address ⇒ String
The public IPv4 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.
-
#security_groups ⇒ Array<Types::GroupIdentifier>
One or more security groups for the instance.
-
#source_dest_check ⇒ Boolean
Specifies whether to enable an instance launched in a VPC to perform NAT.
-
#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
[EC2-VPC] The ID of the subnet in which the instance is running.
-
#tags ⇒ Array<Types::Tag>
Any tags assigned to the instance.
-
#virtualization_type ⇒ String
The virtualization type of the instance.
-
#vpc_id ⇒ String
[EC2-VPC] 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
- #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?
- #identifiers ⇒ Object deprecated private Deprecated.
- #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 ‘true` if this resource is loaded.
- #decrypt_windows_password(key_pair_path) ⇒ String
-
#exists?(options = {}) ⇒ Boolean
Returns ‘true` if the Instance exists.
-
#initialize(*args) ⇒ Instance
constructor
A new instance of Instance.
- #load ⇒ self (also: #reload)
-
#wait_until(options = {}, &block) ⇒ Resource
deprecated
Deprecated.
Use [Aws::EC2::Client] #wait_until instead
- #wait_until_exists(options = {}) ⇒ Instance
- #wait_until_running(options = {}) ⇒ Instance
- #wait_until_stopped(options = {}) ⇒ Instance
- #wait_until_terminated(options = {}) ⇒ Instance
Constructor Details
#initialize(id, options = {}) ⇒ Instance #initialize(options = {}) ⇒ Instance
Returns a new instance of Instance.
19 20 21 22 23 24 |
# File 'lib/aws-sdk-ec2/instance.rb', line 19 def initialize(*args) = Hash === args.last ? args.pop.dup : {} @id = extract_id(args, ) @data = .delete(:data) @client = .delete(:client) || Client.new() end |
Instance Method Details
#ami_launch_index ⇒ Integer
The AMI launch index, which can be used to find this instance in the launch group.
37 38 39 |
# File 'lib/aws-sdk-ec2/instance.rb', line 37 def ami_launch_index data[:ami_launch_index] end |
#architecture ⇒ String
The architecture of the image.
164 165 166 |
# File 'lib/aws-sdk-ec2/instance.rb', line 164 def architecture data[:architecture] end |
#attach_classic_link_vpc(options = {}) ⇒ Types::AttachClassicLinkVpcResult
559 560 561 562 563 |
# File 'lib/aws-sdk-ec2/instance.rb', line 559 def attach_classic_link_vpc( = {}) = .merge(instance_id: @id) resp = @client.attach_classic_link_vpc() resp.data end |
#attach_volume(options = {}) ⇒ Types::VolumeAttachment
584 585 586 587 588 |
# File 'lib/aws-sdk-ec2/instance.rb', line 584 def attach_volume( = {}) = .merge(instance_id: @id) resp = @client.attach_volume() resp.data end |
#block_device_mappings ⇒ Array<Types::InstanceBlockDeviceMapping>
Any block device mapping entries for the instance.
170 171 172 |
# File 'lib/aws-sdk-ec2/instance.rb', line 170 def block_device_mappings data[:block_device_mappings] end |
#capacity_reservation_id ⇒ String
The ID of the Capacity Reservation.
300 301 302 |
# File 'lib/aws-sdk-ec2/instance.rb', line 300 def capacity_reservation_id data[:capacity_reservation_id] end |
#capacity_reservation_specification ⇒ Types::CapacityReservationSpecificationResponse
Information about the Capacity Reservation targeting option.
306 307 308 |
# File 'lib/aws-sdk-ec2/instance.rb', line 306 def capacity_reservation_specification data[:capacity_reservation_specification] end |
#classic_address ⇒ ClassicAddress?
1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 |
# File 'lib/aws-sdk-ec2/instance.rb', line 1225 def classic_address if data[:public_ip_address] ClassicAddress.new( public_ip: data[:public_ip_address], client: @client ) else nil end end |
#client_token ⇒ String
The idempotency token you provided when you launched the instance, if applicable.
177 178 179 |
# File 'lib/aws-sdk-ec2/instance.rb', line 177 def client_token data[:client_token] end |
#console_output(options = {}) ⇒ Types::GetConsoleOutputResult
607 608 609 610 611 |
# File 'lib/aws-sdk-ec2/instance.rb', line 607 def console_output( = {}) = .merge(instance_id: @id) resp = @client.get_console_output() resp.data end |
#cpu_options ⇒ Types::CpuOptions
The CPU options for the instance.
294 295 296 |
# File 'lib/aws-sdk-ec2/instance.rb', line 294 def data[:cpu_options] end |
#create_image(options = {}) ⇒ Image
663 664 665 666 667 668 669 670 |
# File 'lib/aws-sdk-ec2/instance.rb', line 663 def create_image( = {}) = .merge(instance_id: @id) resp = @client.create_image() Image.new( id: resp.data.image_id, client: @client ) end |
#create_tags(options = {}) ⇒ Tag::Collection
694 695 696 697 698 699 700 701 702 703 704 705 706 707 |
# File 'lib/aws-sdk-ec2/instance.rb', line 694 def ( = {}) batch = [] = Aws::Util.deep_merge(, resources: [@id]) resp = @client.() [: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 |
#data ⇒ Types::Instance
Returns the data for this Aws::EC2::Instance. Calls Client#describe_instances if #data_loaded? is ‘false`.
345 346 347 348 |
# File 'lib/aws-sdk-ec2/instance.rb', line 345 def data load unless @data @data end |
#data_loaded? ⇒ Boolean
353 354 355 |
# File 'lib/aws-sdk-ec2/instance.rb', line 353 def data_loaded? !!@data end |
#decrypt_windows_password(key_pair_path) ⇒ String
9 10 11 12 13 14 |
# File '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
726 727 728 729 730 |
# File 'lib/aws-sdk-ec2/instance.rb', line 726 def describe_attribute( = {}) = .merge(instance_id: @id) resp = @client.describe_instance_attribute() resp.data end |
#detach_classic_link_vpc(options = {}) ⇒ Types::DetachClassicLinkVpcResult
747 748 749 750 751 |
# File 'lib/aws-sdk-ec2/instance.rb', line 747 def detach_classic_link_vpc( = {}) = .merge(instance_id: @id) resp = @client.detach_classic_link_vpc() resp.data end |
#detach_volume(options = {}) ⇒ Types::VolumeAttachment
781 782 783 784 785 |
# File 'lib/aws-sdk-ec2/instance.rb', line 781 def detach_volume( = {}) = .merge(instance_id: @id) resp = @client.detach_volume() 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.
187 188 189 |
# File 'lib/aws-sdk-ec2/instance.rb', line 187 def ebs_optimized data[:ebs_optimized] end |
#elastic_gpu_associations ⇒ Array<Types::ElasticGpuAssociation>
The Elastic GPU associated with the instance.
217 218 219 |
# File 'lib/aws-sdk-ec2/instance.rb', line 217 def elastic_gpu_associations data[:elastic_gpu_associations] end |
#elastic_inference_accelerator_associations ⇒ Array<Types::ElasticInferenceAcceleratorAssociation>
The elastic inference accelerator associated with the instance.
223 224 225 |
# File 'lib/aws-sdk-ec2/instance.rb', line 223 def elastic_inference_accelerator_associations data[:elastic_inference_accelerator_associations] end |
#ena_support ⇒ Boolean
Specifies whether enhanced networking with ENA is enabled.
193 194 195 |
# File 'lib/aws-sdk-ec2/instance.rb', line 193 def ena_support data[:ena_support] end |
#exists?(options = {}) ⇒ Boolean
Returns ‘true` if the Instance exists.
360 361 362 363 364 365 366 367 368 369 |
# File 'lib/aws-sdk-ec2/instance.rb', line 360 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.
312 313 314 |
# File 'lib/aws-sdk-ec2/instance.rb', line 312 def data[:hibernation_options] end |
#hypervisor ⇒ String
The hypervisor type of the instance.
199 200 201 |
# File 'lib/aws-sdk-ec2/instance.rb', line 199 def hypervisor data[:hypervisor] end |
#iam_instance_profile ⇒ Types::IamInstanceProfile
The IAM instance profile associated with the instance, if applicable.
205 206 207 |
# File 'lib/aws-sdk-ec2/instance.rb', line 205 def iam_instance_profile data[:iam_instance_profile] end |
#id ⇒ String Also known as: instance_id
29 30 31 |
# File 'lib/aws-sdk-ec2/instance.rb', line 29 def id @id end |
#identifiers ⇒ Object
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.
1482 1483 1484 |
# File 'lib/aws-sdk-ec2/instance.rb', line 1482 def identifiers { id: @id } end |
#image ⇒ Image?
1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 |
# File 'lib/aws-sdk-ec2/instance.rb', line 1237 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.
43 44 45 |
# File 'lib/aws-sdk-ec2/instance.rb', line 43 def image_id data[:image_id] end |
#instance_lifecycle ⇒ String
Indicates whether this is a Spot Instance or a Scheduled Instance.
211 212 213 |
# File 'lib/aws-sdk-ec2/instance.rb', line 211 def instance_lifecycle data[:instance_lifecycle] end |
#instance_type ⇒ String
The instance type.
49 50 51 |
# File 'lib/aws-sdk-ec2/instance.rb', line 49 def instance_type data[:instance_type] end |
#kernel_id ⇒ String
The kernel associated with this instance, if applicable.
55 56 57 |
# File 'lib/aws-sdk-ec2/instance.rb', line 55 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.
62 63 64 |
# File 'lib/aws-sdk-ec2/instance.rb', line 62 def key_name data[:key_name] end |
#key_pair ⇒ KeyPairInfo?
1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 |
# File 'lib/aws-sdk-ec2/instance.rb', line 1249 def key_pair if data[:key_name] KeyPairInfo.new( name: data[:key_name], client: @client ) else nil end end |
#launch_time ⇒ Time
The time the instance was launched.
68 69 70 |
# File 'lib/aws-sdk-ec2/instance.rb', line 68 def launch_time data[:launch_time] end |
#licenses ⇒ Array<Types::LicenseConfiguration>
The license configurations.
318 319 320 |
# File 'lib/aws-sdk-ec2/instance.rb', line 318 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
335 336 337 338 339 |
# File 'lib/aws-sdk-ec2/instance.rb', line 335 def load resp = @client.describe_instances(instance_ids: [@id]) @data = resp.reservations[0].instances[0] self end |
#modify_attribute(options = {}) ⇒ EmptyStructure
920 921 922 923 924 |
# File 'lib/aws-sdk-ec2/instance.rb', line 920 def modify_attribute( = {}) = .merge(instance_id: @id) resp = @client.modify_instance_attribute() resp.data end |
#monitor(options = {}) ⇒ Types::MonitorInstancesResult
938 939 940 941 942 |
# File 'lib/aws-sdk-ec2/instance.rb', line 938 def monitor( = {}) = Aws::Util.deep_merge(, instance_ids: [@id]) resp = @client.monitor_instances() resp.data end |
#monitoring ⇒ Types::Monitoring
The monitoring for the instance.
74 75 76 |
# File 'lib/aws-sdk-ec2/instance.rb', line 74 def monitoring data[:monitoring] end |
#network_interfaces ⇒ NetworkInterface::Collection
1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 |
# File 'lib/aws-sdk-ec2/instance.rb', line 1261 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
956 957 958 959 960 |
# File 'lib/aws-sdk-ec2/instance.rb', line 956 def password_data( = {}) = .merge(instance_id: @id) resp = @client.get_password_data() resp.data end |
#placement ⇒ Types::Placement
The location where the instance launched, if applicable.
80 81 82 |
# File 'lib/aws-sdk-ec2/instance.rb', line 80 def placement data[:placement] end |
#placement_group ⇒ PlacementGroup?
1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 |
# File 'lib/aws-sdk-ec2/instance.rb', line 1274 def placement_group if data[:placement][:group_name] PlacementGroup.new( name: data[:placement][:group_name], client: @client ) else nil end end |
#platform ⇒ String
The value is ‘Windows` for Windows instances; otherwise blank.
86 87 88 |
# File 'lib/aws-sdk-ec2/instance.rb', line 86 def platform data[:platform] 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.
[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.
100 101 102 |
# File 'lib/aws-sdk-ec2/instance.rb', line 100 def private_dns_name data[:private_dns_name] end |
#private_ip_address ⇒ String
The private IPv4 address assigned to the instance.
106 107 108 |
# File 'lib/aws-sdk-ec2/instance.rb', line 106 def private_ip_address data[:private_ip_address] end |
#product_codes ⇒ Array<Types::ProductCode>
The product codes attached to this instance, if applicable.
112 113 114 |
# File 'lib/aws-sdk-ec2/instance.rb', line 112 def product_codes data[:product_codes] end |
#public_dns_name ⇒ String
(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.
121 122 123 |
# File 'lib/aws-sdk-ec2/instance.rb', line 121 def public_dns_name data[:public_dns_name] end |
#public_ip_address ⇒ String
The public IPv4 address assigned to the instance, if applicable.
127 128 129 |
# File 'lib/aws-sdk-ec2/instance.rb', line 127 def public_ip_address data[:public_ip_address] end |
#ramdisk_id ⇒ String
The RAM disk associated with this instance, if applicable.
133 134 135 |
# File 'lib/aws-sdk-ec2/instance.rb', line 133 def ramdisk_id data[:ramdisk_id] end |
#reboot(options = {}) ⇒ EmptyStructure
974 975 976 977 978 |
# File 'lib/aws-sdk-ec2/instance.rb', line 974 def reboot( = {}) = Aws::Util.deep_merge(, instance_ids: [@id]) resp = @client.reboot_instances() resp.data end |
#report_status(options = {}) ⇒ EmptyStructure
1033 1034 1035 1036 1037 |
# File 'lib/aws-sdk-ec2/instance.rb', line 1033 def report_status( = {}) = Aws::Util.deep_merge(, instances: [@id]) resp = @client.report_instance_status() resp.data end |
#reset_attribute(options = {}) ⇒ EmptyStructure
1058 1059 1060 1061 1062 |
# File 'lib/aws-sdk-ec2/instance.rb', line 1058 def reset_attribute( = {}) = .merge(instance_id: @id) resp = @client.reset_instance_attribute() resp.data end |
#reset_kernel(options = {}) ⇒ EmptyStructure
1076 1077 1078 1079 1080 1081 1082 1083 |
# File 'lib/aws-sdk-ec2/instance.rb', line 1076 def reset_kernel( = {}) = .merge( instance_id: @id, attribute: "kernel" ) resp = @client.reset_instance_attribute() resp.data end |
#reset_ramdisk(options = {}) ⇒ EmptyStructure
1097 1098 1099 1100 1101 1102 1103 1104 |
# File 'lib/aws-sdk-ec2/instance.rb', line 1097 def reset_ramdisk( = {}) = .merge( instance_id: @id, attribute: "ramdisk" ) resp = @client.reset_instance_attribute() resp.data end |
#reset_source_dest_check(options = {}) ⇒ EmptyStructure
1118 1119 1120 1121 1122 1123 1124 1125 |
# File 'lib/aws-sdk-ec2/instance.rb', line 1118 def reset_source_dest_check( = {}) = .merge( instance_id: @id, attribute: "sourceDestCheck" ) resp = @client.reset_instance_attribute() resp.data end |
#root_device_name ⇒ String
The device name of the root device volume (for example, ‘/dev/sda1`).
229 230 231 |
# File 'lib/aws-sdk-ec2/instance.rb', line 229 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.
236 237 238 |
# File 'lib/aws-sdk-ec2/instance.rb', line 236 def root_device_type data[:root_device_type] end |
#security_groups ⇒ Array<Types::GroupIdentifier>
One or more security groups for the instance.
242 243 244 |
# File 'lib/aws-sdk-ec2/instance.rb', line 242 def security_groups data[:security_groups] end |
#source_dest_check ⇒ Boolean
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*.
[1]: docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_NAT_Instance.html
257 258 259 |
# File 'lib/aws-sdk-ec2/instance.rb', line 257 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.
263 264 265 |
# File 'lib/aws-sdk-ec2/instance.rb', line 263 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.
270 271 272 |
# File 'lib/aws-sdk-ec2/instance.rb', line 270 def sriov_net_support data[:sriov_net_support] end |
#start(options = {}) ⇒ Types::StartInstancesResult
1142 1143 1144 1145 1146 |
# File 'lib/aws-sdk-ec2/instance.rb', line 1142 def start( = {}) = Aws::Util.deep_merge(, instance_ids: [@id]) resp = @client.start_instances() resp.data end |
#state ⇒ Types::InstanceState
The current state of the instance.
139 140 141 |
# File 'lib/aws-sdk-ec2/instance.rb', line 139 def state data[:state] end |
#state_reason ⇒ Types::StateReason
The reason for the most recent state transition.
276 277 278 |
# File 'lib/aws-sdk-ec2/instance.rb', line 276 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.
146 147 148 |
# File 'lib/aws-sdk-ec2/instance.rb', line 146 def state_transition_reason data[:state_transition_reason] end |
#stop(options = {}) ⇒ Types::StopInstancesResult
1180 1181 1182 1183 1184 |
# File 'lib/aws-sdk-ec2/instance.rb', line 1180 def stop( = {}) = Aws::Util.deep_merge(, instance_ids: [@id]) resp = @client.stop_instances() resp.data end |
#subnet ⇒ Subnet?
1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 |
# File 'lib/aws-sdk-ec2/instance.rb', line 1286 def subnet if data[:subnet_id] Subnet.new( id: data[:subnet_id], client: @client ) else nil end end |
#subnet_id ⇒ String
[EC2-VPC] The ID of the subnet in which the instance is running.
152 153 154 |
# File 'lib/aws-sdk-ec2/instance.rb', line 152 def subnet_id data[:subnet_id] end |
#tags ⇒ Array<Types::Tag>
Any tags assigned to the instance.
282 283 284 |
# File 'lib/aws-sdk-ec2/instance.rb', line 282 def data[:tags] end |
#terminate(options = {}) ⇒ Types::TerminateInstancesResult
1198 1199 1200 1201 1202 |
# File 'lib/aws-sdk-ec2/instance.rb', line 1198 def terminate( = {}) = Aws::Util.deep_merge(, instance_ids: [@id]) resp = @client.terminate_instances() resp.data end |
#unmonitor(options = {}) ⇒ Types::UnmonitorInstancesResult
1216 1217 1218 1219 1220 |
# File 'lib/aws-sdk-ec2/instance.rb', line 1216 def unmonitor( = {}) = Aws::Util.deep_merge(, instance_ids: [@id]) resp = @client.unmonitor_instances() resp.data end |
#virtualization_type ⇒ String
The virtualization type of the instance.
288 289 290 |
# File 'lib/aws-sdk-ec2/instance.rb', line 288 def virtualization_type data[:virtualization_type] end |
#volumes(options = {}) ⇒ Volume::Collection
1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 |
# File 'lib/aws-sdk-ec2/instance.rb', line 1366 def volumes( = {}) batches = Enumerator.new do |y| = Aws::Util.deep_merge(, filters: [{ name: "attachment.instance-id", values: [@id] }]) resp = @client.describe_volumes() 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?
1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 |
# File 'lib/aws-sdk-ec2/instance.rb', line 1389 def vpc if data[:vpc_id] Vpc.new( id: data[:vpc_id], client: @client ) else nil end end |
#vpc_addresses(options = {}) ⇒ VpcAddress::Collection
1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 |
# File 'lib/aws-sdk-ec2/instance.rb', line 1460 def vpc_addresses( = {}) batches = Enumerator.new do |y| batch = [] = Aws::Util.deep_merge(, filters: [{ name: "instance-id", values: [@id] }]) resp = @client.describe_addresses() 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
[EC2-VPC] The ID of the VPC in which the instance is running.
158 159 160 |
# File 'lib/aws-sdk-ec2/instance.rb', line 158 def vpc_id data[:vpc_id] end |
#wait_until(options = {}, &block) ⇒ 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) {|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
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 |
# File 'lib/aws-sdk-ec2/instance.rb', line 521 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::Waiters::Waiter.new().wait({}) end |
#wait_until_exists(options = {}) ⇒ Instance
377 378 379 380 381 382 383 384 385 386 387 |
# File 'lib/aws-sdk-ec2/instance.rb', line 377 def wait_until_exists( = {}) , params = () waiter = Waiters::InstanceExists.new() 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
395 396 397 398 399 400 401 402 403 404 405 |
# File 'lib/aws-sdk-ec2/instance.rb', line 395 def wait_until_running( = {}) , params = () waiter = Waiters::InstanceRunning.new() 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
413 414 415 416 417 418 419 420 421 422 423 |
# File 'lib/aws-sdk-ec2/instance.rb', line 413 def wait_until_stopped( = {}) , params = () waiter = Waiters::InstanceStopped.new() 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
431 432 433 434 435 436 437 438 439 440 441 |
# File 'lib/aws-sdk-ec2/instance.rb', line 431 def wait_until_terminated( = {}) , params = () waiter = Waiters::InstanceTerminated.new() 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 |