Class: Aws::EC2::Instance

Inherits:
Object
  • Object
show all
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

Actions collapse

Associations collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Instance.

Overloads:

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

    Parameters:

    • id (String)

    Options Hash (options):

  • #initialize(options = {}) ⇒ Instance

    Options Hash (options):

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


22
23
24
25
26
27
28
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.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

#ami_launch_indexInteger

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

Returns:

  • (Integer)


389
390
391
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 389

def ami_launch_index
  data[:ami_launch_index]
end

#architectureString

The architecture of the image.

Returns:

  • (String)


40
41
42
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 40

def architecture
  data[:architecture]
end

Examples:

Request syntax with placeholder values


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

Parameters:

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

    ({})

Options Hash (options):

  • :dry_run (Boolean)

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

  • :vpc_id (required, String)

    The ID of the ClassicLink-enabled VPC.

  • :groups (required, Array<String>)

    The IDs of the security groups. You cannot specify security groups from a different VPC.

Returns:



723
724
725
726
727
728
729
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 723

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

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

Examples:

Request syntax with placeholder values


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

Parameters:

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

    ({})

Options Hash (options):

  • :device (required, String)

    The device name (for example, /dev/sdh or xvdh).

  • :volume_id (required, String)

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

  • :ebs_card_index (Integer)

    The index of the EBS card. Some instance types support multiple EBS cards. The default EBS card index is 0.

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



754
755
756
757
758
759
760
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 754

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

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

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.

The operating system contained in the AMI must be configured to support the specified boot mode.

For more information, see Boot modes in the Amazon EC2 User Guide.

Returns:

  • (String)


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_idString

The ID of the Capacity Block.

For P5 instances, a Capacity Block ID refers to a group of instances. For Trn2u instances, a capacity block ID refers to an EC2 UltraServer.

Returns:

  • (String)


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_idString

The ID of the Capacity Reservation.

Returns:

  • (String)


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_specificationTypes::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_addressClassicAddress?

Returns:



1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1622

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

#clientClient

Returns:



475
476
477
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 475

def client
  @client
end

#client_tokenString

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

Returns:

  • (String)


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

Examples:

Request syntax with placeholder values


instance.console_output({
  latest: false,
  dry_run: false,
})

Parameters:

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

    ({})

Options Hash (options):

  • :latest (Boolean)

    When enabled, retrieves the latest console output for the instance.

    Default: disabled (false)

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the operation, 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:



779
780
781
782
783
784
785
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 779

def console_output(options = {})
  options = options.merge(instance_id: @id)
  resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
    @client.get_console_output(options)
  end
  resp.data
end

#cpu_optionsTypes::CpuOptions

The CPU options for the instance.

Returns:



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

def cpu_options
  data[:cpu_options]
end

#create_image(options = {}) ⇒ Image

Examples:

Request syntax with placeholder values


image = instance.create_image({
  tag_specifications: [
    {
      resource_type: "capacity-reservation", # accepts capacity-reservation, client-vpn-endpoint, customer-gateway, carrier-gateway, coip-pool, declarative-policies-report, dedicated-host, dhcp-options, egress-only-internet-gateway, elastic-ip, elastic-gpu, export-image-task, export-instance-task, fleet, fpga-image, host-reservation, image, image-usage-report, import-image-task, import-snapshot-task, instance, instance-event-window, internet-gateway, ipam, ipam-pool, ipam-scope, ipv4pool-ec2, ipv6pool-ec2, key-pair, launch-template, local-gateway, local-gateway-route-table, local-gateway-virtual-interface, local-gateway-virtual-interface-group, local-gateway-route-table-vpc-association, local-gateway-route-table-virtual-interface-group-association, natgateway, network-acl, network-interface, network-insights-analysis, network-insights-path, network-insights-access-scope, network-insights-access-scope-analysis, outpost-lag, placement-group, prefix-list, replace-root-volume-task, reserved-instances, route-table, security-group, security-group-rule, service-link-virtual-interface, snapshot, spot-fleet-request, spot-instances-request, subnet, subnet-cidr-reservation, traffic-mirror-filter, traffic-mirror-session, traffic-mirror-target, transit-gateway, transit-gateway-attachment, transit-gateway-connect-peer, transit-gateway-multicast-domain, transit-gateway-policy-table, transit-gateway-metering-policy, transit-gateway-route-table, transit-gateway-route-table-announcement, volume, vpc, vpc-endpoint, vpc-endpoint-connection, vpc-endpoint-service, vpc-endpoint-service-permission, vpc-peering-connection, vpn-connection, vpn-gateway, vpc-flow-log, capacity-reservation-fleet, traffic-mirror-filter-rule, vpc-endpoint-connection-device-type, verified-access-instance, verified-access-group, verified-access-endpoint, verified-access-policy, verified-access-trust-provider, vpn-connection-device-type, vpc-block-public-access-exclusion, vpc-encryption-control, route-server, route-server-endpoint, route-server-peer, ipam-resource-discovery, ipam-resource-discovery-association, instance-connect-endpoint, verified-access-endpoint-target, ipam-external-resource-verification-token, capacity-block, mac-modification-task, ipam-prefix-list-resolver, ipam-policy, ipam-prefix-list-resolver-target, capacity-manager-data-export, vpn-concentrator
      tags: [
        {
          key: "String",
          value: "String",
        },
      ],
    },
  ],
  snapshot_location: "regional", # accepts regional, local
  dry_run: false,
  name: "String", # required
  description: "String",
  no_reboot: false,
  block_device_mappings: [
    {
      ebs: {
        delete_on_termination: false,
        iops: 1,
        snapshot_id: "SnapshotId",
        volume_size: 1,
        volume_type: "standard", # accepts standard, io1, io2, gp2, sc1, st1, gp3
        kms_key_id: "String",
        throughput: 1,
        outpost_arn: "String",
        availability_zone: "String",
        encrypted: false,
        volume_initialization_rate: 1,
        availability_zone_id: "String",
        ebs_card_index: 1,
      },
      no_device: "String",
      device_name: "String",
      virtual_name: "String",
    },
  ],
})

Parameters:

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

    ({})

Options Hash (options):

  • :tag_specifications (Array<Types::TagSpecification>)

    The tags to apply to the AMI and snapshots on creation. You can tag the AMI, the snapshots, or both.

    • To tag the AMI, the value for ResourceType must be image.

    • To tag the snapshots that are created of the root volume and of other Amazon EBS volumes that are attached to the instance, the value for ResourceType must be snapshot. The same tag is applied to all of the snapshots that are created.

    If you specify other values for ResourceType, the request fails.

    To tag an AMI or snapshot after it has been created, see CreateTags.

  • :snapshot_location (String)

    Only supported for instances in Local Zones. If the source instance is not in a Local Zone, omit this parameter.

    The Amazon S3 location where the snapshots will be stored.

    • To create local snapshots in the same Local Zone as the source instance, specify local.

    • To create regional snapshots in the parent Region of the Local Zone, specify regional or omit this parameter.

    Default: regional

  • :dry_run (Boolean)

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

  • :name (required, String)

    A name for the new image.

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

  • :description (String)

    A description for the new image.

  • :no_reboot (Boolean)

    Indicates whether or not the instance should be automatically rebooted before creating the image. Specify one of the following values:

    • true - The instance is not rebooted before creating the image. This creates crash-consistent snapshots that include only the data that has been written to the volumes at the time the snapshots are created. Buffered data and data in memory that has not yet been written to the volumes is not included in the snapshots.

    • false - The instance is rebooted before creating the image. This ensures that all buffered data and data in memory is written to the volumes before the snapshots are created.

    Default: false

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

    The block device mappings.

    When using the CreateImage action:

    • You can't change the volume size using the VolumeSize parameter. If you want a different volume size, you must first change the volume size of the source instance.

    • You can't modify the encryption status of existing volumes or snapshots. To create an AMI with volumes or snapshots that have a different encryption status (for example, where the source volume and snapshots are unencrypted, and you want to create an AMI with encrypted volumes or snapshots), copy the image instead.

    • The only option that can be changed for existing mappings or snapshots is DeleteOnTermination.

Returns:



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

def create_image(options = {})
  options = options.merge(instance_id: @id)
  resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
    @client.create_image(options)
  end
  Image.new(
    id: resp.data.image_id,
    client: @client
  )
end

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

Examples:

Request syntax with placeholder values


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

Parameters:

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

    ({})

Options Hash (options):

  • :dry_run (Boolean)

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

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

    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:



943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 943

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

#current_instance_boot_modeString

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.

Returns:

  • (String)


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

#dataTypes::Instance

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

Returns:



497
498
499
500
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 497

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.



505
506
507
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 505

def data_loaded?
  !!@data
end

#decrypt_windows_password(key_pair_path) ⇒ String

Parameters:

  • key_pair_path (String, Pathname)

Returns:

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

Examples:

Request syntax with placeholder values


tag = instance.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:



990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 990

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

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

Examples:

Request syntax with placeholder values


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

Parameters:

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

    ({})

Options Hash (options):

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the operation, 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.

  • :attribute (required, String)

    The instance attribute.

    Note that the enaSupport attribute is not supported.

Returns:



1024
1025
1026
1027
1028
1029
1030
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1024

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

Examples:

Request syntax with placeholder values


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

Parameters:

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

    ({})

Options Hash (options):

  • :dry_run (Boolean)

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

  • :vpc_id (required, String)

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

Returns:



1047
1048
1049
1050
1051
1052
1053
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1047

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

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

Examples:

Request syntax with placeholder values


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

Parameters:

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

    ({})

Options Hash (options):

  • :device (String)

    The device name.

  • :force (Boolean)

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

  • :volume_id (required, String)

    The ID of the volume.

  • :dry_run (Boolean)

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

Returns:



1083
1084
1085
1086
1087
1088
1089
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1083

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

#ebs_optimizedBoolean

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

Returns:

  • (Boolean)


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_associationsArray<Types::ElasticGpuAssociation>

Deprecated.

Amazon Elastic Graphics reached end of life on January 8, 2024.

Returns:



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_associationsArray<Types::ElasticInferenceAcceleratorAssociation>

Deprecated

Amazon Elastic Inference is no longer available.



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_supportBoolean

Specifies whether enhanced networking with ENA is enabled.

Returns:

  • (Boolean)


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

def ena_support
  data[:ena_support]
end

#enclave_optionsTypes::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 enclave_options
  data[:enclave_options]
end

#exists?(options = {}) ⇒ Boolean

Returns true if the Instance exists.

Parameters:

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

    ({})

Returns:

  • (Boolean)

    Returns true if the Instance exists.



512
513
514
515
516
517
518
519
520
521
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 512

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

#hibernation_optionsTypes::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 hibernation_options
  data[:hibernation_options]
end

#hypervisorString

The hypervisor type of the instance. The value xen is used for both Xen and Nitro hypervisors.

Returns:

  • (String)


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

def hypervisor
  data[:hypervisor]
end

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

#idString Also known as: instance_id

Returns:

  • (String)


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

def id
  @id
end

#imageImage?

Returns:



1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1634

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

#image_idString

The ID of the AMI used to launch the instance.

Returns:

  • (String)


335
336
337
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 335

def image_id
  data[:image_id]
end

#instance_lifecycleString

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

Returns:

  • (String)


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

def instance_lifecycle
  data[:instance_lifecycle]
end

#instance_typeString

The instance type.

Returns:

  • (String)


401
402
403
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 401

def instance_type
  data[:instance_type]
end

#ipv_6_addressString

The IPv6 address assigned to the instance.

Returns:

  • (String)


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_idString

The kernel associated with this instance, if applicable.

Returns:

  • (String)


421
422
423
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 421

def kernel_id
  data[:kernel_id]
end

#key_nameString

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

Returns:

  • (String)


382
383
384
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 382

def key_name
  data[:key_name]
end

#key_pairKeyPairInfo?

Returns:



1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1646

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

#launch_timeTime

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.

Returns:

  • (Time)


409
410
411
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 409

def launch_time
  data[:launch_time]
end

#licensesArray<Types::LicenseConfiguration>

The license configurations for the instance.

Returns:



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

def licenses
  data[:licenses]
end

#loadself Also known as: reload

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

instance.reload.data

Returns:

  • (self)


485
486
487
488
489
490
491
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 485

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_optionsTypes::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 maintenance_options
  data[:maintenance_options]
end

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

Examples:

Request syntax with placeholder values


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

Parameters:

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

    ({})

Options Hash (options):

  • :source_dest_check (Types::AttributeBooleanValue)

    Enable or disable source/destination checks, which ensure that the instance is either the source or the destination of any traffic that it receives. If the value is true, source/destination checks are enabled; otherwise, they are disabled. The default value is true. You must disable source/destination checks if the instance runs services such as network address translation, routing, or firewalls.

  • :disable_api_stop (Types::AttributeBooleanValue)

    Indicates whether an instance is enabled for stop protection. For more information, see Enable stop protection for your instance.

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the operation, 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.

  • :attribute (String)

    The name of the attribute to modify.

    When changing the instance type: If the original instance type is configured for configurable bandwidth, and the desired instance type doesn't support configurable bandwidth, first set the existing bandwidth configuration to default using the ModifyInstanceNetworkPerformanceOptions operation.

    You can modify the following attributes only: disableApiTermination | instanceType | kernel | ramdisk | instanceInitiatedShutdownBehavior | blockDeviceMapping | userData | sourceDestCheck | groupSet | ebsOptimized | sriovNetSupport | enaSupport | nvmeSupport | disableApiStop | enclaveOptions

  • :value (String)

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

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

    Modifies the DeleteOnTermination attribute for volumes that are currently attached. The volume must be owned by the caller. If no value is specified for DeleteOnTermination, the default is true and the volume is deleted when the instance is terminated. You can't modify the DeleteOnTermination attribute for volumes that are attached to Amazon Web Services-managed resources.

    To add instance store volumes to an Amazon EBS-backed instance, you must add them when you launch the instance. For more information, see Update the block device mapping when launching an instance in the Amazon EC2 User Guide.

  • :disable_api_termination (Types::AttributeBooleanValue)

    Enable or disable termination protection for the instance. If the value is true, you can't terminate the instance using the Amazon EC2 console, command line interface, or API. You can't enable termination protection for Spot Instances.

  • :instance_type (Types::AttributeValue)

    Changes the instance type to the specified value. For more information, see Instance types in the Amazon EC2 User Guide. If the instance type is not valid, the error returned is InvalidInstanceAttributeValue.

  • :kernel (Types::AttributeValue)

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

  • :ramdisk (Types::AttributeValue)

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

  • :user_data (Types::BlobAttributeValue)

    Changes the instance's user data to the specified value. User data must be base64-encoded. Depending on the tool or SDK that you're using, the base64-encoding might be performed for you. For more information, see Work with instance user data.

  • :instance_initiated_shutdown_behavior (Types::AttributeValue)

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

  • :groups (Array<String>)

    Replaces the security groups of the instance with the specified security groups. You must specify the ID of at least one security group, even if it's just the default security group for the VPC.

  • :ebs_optimized (Types::AttributeBooleanValue)

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

  • :sriov_net_support (Types::AttributeValue)

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

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

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

  • :ena_support (Types::AttributeBooleanValue)

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

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

Returns:

  • (EmptyStructure)


1260
1261
1262
1263
1264
1265
1266
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1260

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

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

Examples:

Request syntax with placeholder values


instance.monitor({
  dry_run: false,
})

Parameters:

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

    ({})

Options Hash (options):

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the operation, 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:



1280
1281
1282
1283
1284
1285
1286
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1280

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

#monitoringTypes::Monitoring

The monitoring for the instance.

Returns:



440
441
442
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 440

def monitoring
  data[:monitoring]
end

#network_interfacesNetworkInterface::Collection



1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1658

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_optionsTypes::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 network_performance_options
  data[:network_performance_options]
end

#operatorTypes::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_arnString

The Amazon Resource Name (ARN) of the Outpost.

Returns:

  • (String)


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

Examples:

Request syntax with placeholder values


instance.password_data({
  dry_run: false,
})

Parameters:

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

    ({})

Options Hash (options):

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the operation, 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:



1300
1301
1302
1303
1304
1305
1306
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1300

def password_data(options = {})
  options = options.merge(instance_id: @id)
  resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
    @client.get_password_data(options)
  end
  resp.data
end

#placementTypes::Placement

The location where the instance launched, if applicable.

Returns:



415
416
417
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 415

def placement
  data[:placement]
end

#placement_groupPlacementGroup?

Returns:



1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1671

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

#platformString

The platform. This value is windows for Windows instances; otherwise, it is empty.

Returns:

  • (String)


434
435
436
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 434

def platform
  data[:platform]
end

#platform_detailsString

The platform details value for the instance. For more information, see AMI billing information fields in the Amazon EC2 User Guide.

Returns:

  • (String)


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_nameString

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

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

Returns:

  • (String)


355
356
357
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 355

def private_dns_name
  data[:private_dns_name]
end

#private_dns_name_optionsTypes::PrivateDnsNameOptionsResponse

The options for the instance hostname.



279
280
281
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 279

def private_dns_name_options
  data[:private_dns_name_options]
end

#private_ip_addressString

The private IPv4 address assigned to the instance.

Returns:

  • (String)


458
459
460
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 458

def private_ip_address
  data[:private_ip_address]
end

#product_codesArray<Types::ProductCode>

The product codes attached to this instance, if applicable.

Returns:



395
396
397
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 395

def product_codes
  data[:product_codes]
end

#public_dns_nameString

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.

Returns:

  • (String)


368
369
370
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 368

def public_dns_name
  data[:public_dns_name]
end

#public_ip_addressString

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.

Returns:

  • (String)


468
469
470
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 468

def public_ip_address
  data[:public_ip_address]
end

#ramdisk_idString

The RAM disk associated with this instance, if applicable.

Returns:

  • (String)


427
428
429
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 427

def ramdisk_id
  data[:ramdisk_id]
end

#reboot(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


instance.reboot({
  dry_run: false,
})

Parameters:

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

    ({})

Options Hash (options):

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the operation, 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)


1320
1321
1322
1323
1324
1325
1326
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1320

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

#report_status(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


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

Parameters:

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

    ({})

Options Hash (options):

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the operation, 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.

  • :status (required, String)

    The status of all instances listed.

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

    The time at which the reported instance health state began.

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

    The time at which the reported instance health state ended.

  • :reason_codes (required, Array<String>)

    The reason codes that describe the health state of your instance.

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

    • unresponsive: My instance is unresponsive.

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

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

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

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

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

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

    • other: [explain using the description parameter]

  • :description (String)

    Descriptive text about the health state of your instance.

Returns:

  • (EmptyStructure)


1380
1381
1382
1383
1384
1385
1386
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1380

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

#reset_attribute(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


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

Parameters:

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

    ({})

Options Hash (options):

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the operation, 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.

  • :attribute (required, String)

    The attribute to reset.

    You can only reset the following attributes: kernel | ramdisk | sourceDestCheck.

Returns:

  • (EmptyStructure)


1406
1407
1408
1409
1410
1411
1412
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1406

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

#reset_kernel(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


instance.reset_kernel({
  dry_run: false,
})

Parameters:

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

    ({})

Options Hash (options):

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the operation, 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)


1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1426

def reset_kernel(options = {})
  options = options.merge(
    instance_id: @id,
    attribute: "kernel"
  )
  resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
    @client.reset_instance_attribute(options)
  end
  resp.data
end

#reset_ramdisk(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


instance.reset_ramdisk({
  dry_run: false,
})

Parameters:

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

    ({})

Options Hash (options):

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the operation, 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)


1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1449

def reset_ramdisk(options = {})
  options = options.merge(
    instance_id: @id,
    attribute: "ramdisk"
  )
  resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
    @client.reset_instance_attribute(options)
  end
  resp.data
end

#reset_source_dest_check(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


instance.reset_source_dest_check({
  dry_run: false,
})

Parameters:

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

    ({})

Options Hash (options):

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the operation, 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)


1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1472

def reset_source_dest_check(options = {})
  options = options.merge(
    instance_id: @id,
    attribute: "sourceDestCheck"
  )
  resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
    @client.reset_instance_attribute(options)
  end
  resp.data
end

#root_device_nameString

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

Returns:

  • (String)


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_typeString

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

Returns:

  • (String)


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

#security_groupsArray<Types::GroupIdentifier>

The security groups for the instance.

Returns:



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_checkBoolean

Indicates whether source/destination checking is enabled.

Returns:

  • (Boolean)


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_idString

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

Returns:

  • (String)


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_supportString

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

Returns:

  • (String)


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

Examples:

Request syntax with placeholder values


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

Parameters:

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

    ({})

Options Hash (options):

  • :additional_info (String)

    Reserved.

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the operation, 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:



1498
1499
1500
1501
1502
1503
1504
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1498

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

#stateTypes::InstanceState

The current state of the instance.



341
342
343
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 341

def state
  data[:state]
end

#state_reasonTypes::StateReason

The reason for the most recent state transition.

Returns:



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_reasonString

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

Returns:

  • (String)


375
376
377
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 375

def state_transition_reason
  data[:state_transition_reason]
end

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

Examples:

Request syntax with placeholder values


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

Parameters:

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

    ({})

Options Hash (options):

  • :hibernate (Boolean)

    Hibernates the instance if the instance was enabled for hibernation at launch. If the instance cannot hibernate successfully, a normal shutdown occurs. For more information, see Hibernate your Amazon EC2 instance in the Amazon EC2 User Guide.

    Default: false

  • :skip_os_shutdown (Boolean)

    Specifies whether to bypass the graceful OS shutdown process when the instance is stopped.

    Bypassing the graceful OS shutdown might result in data loss or corruption (for example, memory contents not flushed to disk or loss of in-flight IOs) or skipped shutdown scripts.

    Default: false

  • :dry_run (Boolean)

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

  • :force (Boolean)

    Forces the instance to stop. The instance will first attempt a graceful shutdown, which includes flushing file system caches and metadata. If the graceful shutdown fails to complete within the timeout period, the instance shuts down forcibly without flushing the file system caches and metadata.

    After using this option, you must perform file system check and repair procedures. This option is not recommended for Windows instances. For more information, see Troubleshoot Amazon EC2 instance stop issues in the Amazon EC2 User Guide.

    Default: false

Returns:



1558
1559
1560
1561
1562
1563
1564
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1558

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

#subnetSubnet?

Returns:



1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1683

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

#subnet_idString

The ID of the subnet in which the instance is running.

Returns:

  • (String)


446
447
448
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 446

def subnet_id
  data[:subnet_id]
end

#tagsArray<Types::Tag>

Any tags assigned to the instance.

Returns:



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

def tags
  data[:tags]
end

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

Examples:

Request syntax with placeholder values


instance.terminate({
  force: false,
  skip_os_shutdown: false,
  dry_run: false,
})

Parameters:

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

    ({})

Options Hash (options):

  • :force (Boolean)

    Forces the instances to terminate. The instance will first attempt a graceful shutdown, which includes flushing file system caches and metadata. If the graceful shutdown fails to complete within the timeout period, the instance shuts down forcibly without flushing the file system caches and metadata.

  • :skip_os_shutdown (Boolean)

    Specifies whether to bypass the graceful OS shutdown process when the instance is terminated.

    Default: false

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the operation, 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:



1591
1592
1593
1594
1595
1596
1597
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1591

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

#tpm_supportString

If the instance is configured for NitroTPM support, the value is v2.0. For more information, see NitroTPM in the Amazon EC2 User Guide.

Returns:

  • (String)


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

Examples:

Request syntax with placeholder values


instance.unmonitor({
  dry_run: false,
})

Parameters:

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

    ({})

Options Hash (options):

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the operation, 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:



1611
1612
1613
1614
1615
1616
1617
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1611

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

#usage_operationString

The usage operation value for the instance. For more information, see AMI billing information fields in the Amazon EC2 User Guide.

Returns:

  • (String)


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_timeTime

The time that the usage operation was last updated.

Returns:

  • (Time)


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_typeString

The virtualization type of the instance.

Returns:

  • (String)


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

Examples:

Request syntax with placeholder values


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

Parameters:

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

    ({})

Options Hash (options):

  • :volume_ids (Array<String>)

    The volume IDs. If not specified, then all volumes are included in the response.

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

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

    The filters.

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

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

    • attachment.device - The device name specified in the block device mapping (for example, /dev/sda1).

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

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

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

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

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

    • encrypted - Indicates whether the volume is encrypted (true | false)

    • fast-restored - Indicates whether the volume was created from a snapshot that is enabled for fast snapshot restore (true | false).

    • multi-attach-enabled - Indicates whether the volume is enabled for Multi-Attach (true | false)

    • operator.managed - A Boolean that indicates whether this is a managed volume.

    • operator.principal - The principal that manages the volume. Only valid for managed volumes, where managed is true.

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

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

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

    • tag:<key> - The key/value combination of a tag assigned to the resource. Use the tag key in the filter name and the tag value as the filter value. For example, to find all resources that have a tag with the key Owner and the value TeamA, specify tag:Owner for the filter name and TeamA for the filter value.

    • tag-key - The key of a tag assigned to the resource. Use this filter to find all resources assigned a tag with a specific key, regardless of the tag value.

    • volume-id - The volume ID.

    • volume-type - The Amazon EBS volume type (gp2 | gp3 | io1 | io2 | st1 | sc1| standard)

Returns:



1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1779

def volumes(options = {})
  batches = Enumerator.new do |y|
    options = Aws::Util.deep_merge(options, filters: [{
      name: "attachment.instance-id",
      values: [@id]
    }])
    resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
      @client.describe_volumes(options)
    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

#vpcVpc?

Returns:



1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1804

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

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

Examples:

Request syntax with placeholder values


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

Parameters:

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

    ({})

Options Hash (options):

  • :public_ips (Array<String>)

    One or more Elastic IP addresses.

    Default: Describes all your Elastic IP addresses.

  • :dry_run (Boolean)

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

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

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

    • allocation-id - The allocation ID for the address.

    • association-id - The association ID for the address.

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

    • network-border-group - A unique set of Availability Zones, Local Zones, or Wavelength Zones from where Amazon Web Services advertises IP addresses.

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

    • network-interface-owner-id - The Amazon Web Services account ID of the owner.

    • private-ip-address - The private IP address associated with the Elastic IP address.

    • public-ip - The Elastic IP address, or the carrier IP address.

    • tag:<key> - The key/value combination of a tag assigned to the resource. Use the tag key in the filter name and the tag value as the filter value. For example, to find all resources that have a tag with the key Owner and the value TeamA, specify tag:Owner for the filter name and TeamA for the filter value.

    • tag-key - The key of a tag assigned to the resource. Use this filter to find all resources assigned a tag with a specific key, regardless of the tag value.

  • :allocation_ids (Array<String>)

    Information about the allocation IDs.

Returns:



1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 1875

def vpc_addresses(options = {})
  batches = Enumerator.new do |y|
    batch = []
    options = Aws::Util.deep_merge(options, filters: [{
      name: "instance-id",
      values: [@id]
    }])
    resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
      @client.describe_addresses(options)
    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_idString

The ID of the VPC in which the instance is running.

Returns:

  • (String)


452
453
454
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 452

def vpc_id
  data[:vpc_id]
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



683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 683

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) ⇒ Instance

Parameters:

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

    ({})

Options Hash (options):

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

Returns:



529
530
531
532
533
534
535
536
537
538
539
540
541
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 529

def wait_until_exists(options = {}, &block)
  options, params = separate_params_and_options(options)
  waiter = Waiters::InstanceExists.new(options)
  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

Parameters:

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

    ({})

Options Hash (options):

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

Returns:



549
550
551
552
553
554
555
556
557
558
559
560
561
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 549

def wait_until_running(options = {}, &block)
  options, params = separate_params_and_options(options)
  waiter = Waiters::InstanceRunning.new(options)
  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

Parameters:

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

    ({})

Options Hash (options):

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

Returns:



569
570
571
572
573
574
575
576
577
578
579
580
581
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/instance.rb', line 569

def wait_until_stopped(options = {}, &block)
  options, params = separate_params_and_options(options)
  waiter = Waiters::InstanceStopped.new(options)
  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

Parameters:

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

    ({})

Options Hash (options):

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

Returns:



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

def wait_until_terminated(options = {}, &block)
  options, params = separate_params_and_options(options)
  waiter = Waiters::InstanceTerminated.new(options)
  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