You are viewing documentation for version 2 of the AWS SDK for Ruby. Version 3 documentation can be found here.

Class: Aws::EC2::Volume

Inherits:
Resources::Resource show all
Defined in:
(unknown)

Instance Attribute Summary collapse

Attributes inherited from Resources::Resource

#client, #identifiers

Instance Method Summary collapse

Methods inherited from Resources::Resource

add_data_attribute, add_identifier, #data, data_attributes, #data_loaded?, identifiers, #load, #wait_until

Methods included from Resources::OperationMethods

#add_batch_operation, #add_operation, #batch_operation, #batch_operation_names, #batch_operations, #operation, #operation_names, #operations

Constructor Details

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

Overloads:

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

    Parameters:

    • id (String)

    Options Hash (options):

    • :client (Client)

      When `:client is not given, the options hash is used to construct a new Client object.

  • #initialize(options = {}) ⇒ Object

    Options Hash (options):

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

      When `:client is not given, the options hash is used to construct a new Client object.

Instance Attribute Details

#attachmentsArray<Types::VolumeAttachment> (readonly)

Information about the volume attachments.

Returns:

#availability_zoneString (readonly)

The Availability Zone for the volume.

Returns:

  • (String)

    The Availability Zone for the volume.

#create_timeTime (readonly)

The time stamp when volume creation was initiated.

Returns:

  • (Time)

    The time stamp when volume creation was initiated.

#encryptedBoolean (readonly)

Indicates whether the volume is encrypted.

Returns:

  • (Boolean)

    Indicates whether the volume is encrypted.

#fast_restoredBoolean (readonly)

Indicates whether the volume was created using fast snapshot restore.

Returns:

  • (Boolean)

    Indicates whether the volume was created using fast snapshot restore.

#idString (readonly)

Returns:

  • (String)

#iopsInteger (readonly)

The number of I/O operations per second (IOPS) that the volume supports. For Provisioned IOPS SSD volumes, this represents the number of IOPS that are provisioned for the volume. For General Purpose SSD volumes, this represents the baseline performance of the volume and the rate at which the volume accumulates I/O credits for bursting. For more information, see Amazon EBS volume types in the Amazon Elastic Compute Cloud User Guide.

Constraints: Range is 100-16,000 IOPS for gp2 volumes and 100 to 64,000 IOPS for io1 and io2 volumes, in most Regions. The maximum IOPS for io1 and io2 of 64,000 is guaranteed only on Nitro-based instances. Other instance families guarantee performance up to 32,000 IOPS.

Condition: This parameter is required for requests to create io1 and io2 volumes; it is not used in requests to create gp2, st1, sc1, or standard volumes.

Returns:

  • (Integer)

    The number of I/O operations per second (IOPS) that the volume supports.

#kms_key_idString (readonly)

The Amazon Resource Name (ARN) of the AWS Key Management Service (AWS KMS) customer master key (CMK) that was used to protect the volume encryption key for the volume.

Returns:

  • (String)

    The Amazon Resource Name (ARN) of the AWS Key Management Service (AWS KMS) customer master key (CMK) that was used to protect the volume encryption key for the volume.

#multi_attach_enabledBoolean (readonly)

Indicates whether Amazon EBS Multi-Attach is enabled.

Returns:

  • (Boolean)

    Indicates whether Amazon EBS Multi-Attach is enabled.

#outpost_arnString (readonly)

The Amazon Resource Name (ARN) of the Outpost.

Returns:

  • (String)

    The Amazon Resource Name (ARN) of the Outpost.

#sizeInteger (readonly)

The size of the volume, in GiBs.

Returns:

  • (Integer)

    The size of the volume, in GiBs.

#snapshot_idString (readonly)

The snapshot from which the volume was created, if applicable.

Returns:

  • (String)

    The snapshot from which the volume was created, if applicable.

#stateString (readonly)

The volume state.

Possible values:

  • creating
  • available
  • in-use
  • deleting
  • deleted
  • error

Returns:

  • (String)

    The volume state.

#tagsArray<Types::Tag> (readonly)

Any tags assigned to the volume.

Returns:

  • (Array<Types::Tag>)

    Any tags assigned to the volume.

#volume_idString (readonly)

The ID of the volume.

Returns:

  • (String)

    The ID of the volume.

#volume_typeString (readonly)

The volume type. This can be gp2 for General Purpose SSD, io1 or io2 for Provisioned IOPS SSD, st1 for Throughput Optimized HDD, sc1 for Cold HDD, or standard for Magnetic volumes.

Possible values:

  • standard
  • io1
  • io2
  • gp2
  • sc1
  • st1

Returns:

  • (String)

    The volume type.

Instance Method Details

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

Attaches an EBS volume to a running or stopped instance and exposes it to the instance with the specified device name.

Encrypted EBS volumes must be attached to instances that support Amazon EBS encryption. For more information, see Amazon EBS Encryption in the Amazon Elastic Compute Cloud User Guide.

After you attach an EBS volume, you must make it available. For more information, see Making an EBS volume available for use.

If a volume has an AWS Marketplace product code:

  • The volume can be attached only to a stopped instance.

  • AWS Marketplace product codes are copied from the volume to the instance.

  • You must be subscribed to the product.

  • The instance type and operating system of the instance must support the product. For example, you can't detach a volume from a Windows instance and attach it to a Linux instance.

For more information, see Attaching Amazon EBS volumes in the Amazon Elastic Compute Cloud User Guide.

Examples:

Request syntax example with placeholder values


volume.attach_to_instance({
  device: "String", # required
  instance_id: "InstanceId", # required
  dry_run: false,
})

Options Hash (options):

  • :device (required, String)

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

  • :instance_id (required, String)

    The ID of the instance.

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

See Also:

#create_snapshot(options = {}) ⇒ Snapshot

Examples:

Request syntax example with placeholder values


volume.create_snapshot({
  description: "String",
  tag_specifications: [
    {
      resource_type: "client-vpn-endpoint", # accepts client-vpn-endpoint, customer-gateway, dedicated-host, dhcp-options, egress-only-internet-gateway, elastic-ip, elastic-gpu, export-image-task, export-instance-task, fleet, fpga-image, host-reservation, image, import-image-task, import-snapshot-task, instance, internet-gateway, key-pair, launch-template, local-gateway-route-table-vpc-association, natgateway, network-acl, network-interface, placement-group, reserved-instances, route-table, security-group, snapshot, spot-fleet-request, spot-instances-request, subnet, traffic-mirror-filter, traffic-mirror-session, traffic-mirror-target, transit-gateway, transit-gateway-attachment, transit-gateway-multicast-domain, transit-gateway-route-table, volume, vpc, vpc-peering-connection, vpn-connection, vpn-gateway, vpc-flow-log
      tags: [
        {
          key: "String",
          value: "String",
        },
      ],
    },
  ],
  dry_run: false,
})

Basic usage

snapshot = volume.create_snapshot(options)
snapshot.id
#=> "snapshot-id"

Options Hash (options):

  • :description (String)

    A description for the snapshot.

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

    The tags to apply to the snapshot during creation.

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

See Also:

#create_tags(options = {}) ⇒ Array<Tag>

Examples:

Request syntax example with placeholder values


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

Basic usage

tags = volume.create_tags(options)
tags.map(&:value)
#=> ["tag-value", ...]

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:

See Also:

#delete(options = {}) ⇒ Struct

Deletes the specified EBS volume. The volume must be in the available state (not attached to an instance).

The volume can remain in the deleting state for several minutes.

For more information, see Deleting an Amazon EBS volume in the Amazon Elastic Compute Cloud User Guide.

Examples:

Request syntax example with placeholder values


volume.delete({
  dry_run: false,
})

Options Hash (options):

  • :dry_run (Boolean)

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

Returns:

  • (Struct)

    Returns an empty response.

See Also:

#delete_tags(options = {}) ⇒ Array<Tag>

Examples:

Request syntax example with placeholder values


volume.delete_tags({
  dry_run: false,
  tags: [
    {
      key: "String",
      value: "String",
    },
  ],
})

Basic usage

tags = volume.delete_tags(options)
tags.map(&:value)
#=> ["tag-value", ...]

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 AWS-generated tags (tags that have the aws: prefix).

Returns:

See Also:

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

Describes the specified attribute of the specified volume. You can specify only one attribute at a time.

For more information about EBS volumes, see Amazon EBS Volumes in the Amazon Elastic Compute Cloud User Guide.

Examples:

Request syntax example with placeholder values


volume.describe_attribute({
  attribute: "autoEnableIO", # required, accepts autoEnableIO, productCodes
  dry_run: false,
})

Options Hash (options):

  • :attribute (required, String)

    The attribute of the volume. This parameter is required.

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

See Also:

#describe_status(options = {}) ⇒ Types::DescribeVolumeStatusResult

Describes the status of the specified volumes. Volume status provides the result of the checks performed on your volumes to determine events that can impair the performance of your volumes. The performance of a volume can be affected if an issue occurs on the volume's underlying host. If the volume's underlying host experiences a power outage or system issue, after the system is restored, there could be data inconsistencies on the volume. Volume events notify you if this occurs. Volume actions notify you if any action needs to be taken in response to the event.

The DescribeVolumeStatus operation provides the following information about the specified volumes:

Status: Reflects the current status of the volume. The possible values are ok, impaired , warning, or insufficient-data. If all checks pass, the overall status of the volume is ok. If the check fails, the overall status is impaired. If the status is insufficient-data, then the checks may still be taking place on your volume at the time. We recommend that you retry the request. For more information about volume status, see Monitoring the status of your volumes in the Amazon Elastic Compute Cloud User Guide.

Events: Reflect the cause of a volume status and may require you to take action. For example, if your volume returns an impaired status, then the volume event might be potential-data-inconsistency. This means that your volume has been affected by an issue with the underlying host, has all I/O operations disabled, and may have inconsistent data.

Actions: Reflect the actions you may have to take in response to an event. For example, if the status of the volume is impaired and the volume event shows potential-data-inconsistency, then the action shows enable-volume-io. This means that you may want to enable the I/O operations for the volume by calling the EnableVolumeIO action and then check the volume for data consistency.

Volume status is based on the volume status checks, and does not reflect the volume state. Therefore, volume status does not indicate volumes in the error state (for example, when a volume is incapable of accepting I/O.)

Examples:

Request syntax example with placeholder values


volume.describe_status({
  filters: [
    {
      name: "String",
      values: ["String"],
    },
  ],
  max_results: 1,
  next_token: "String",
  dry_run: false,
})

Options Hash (options):

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

    The filters.

    • action.code - The action code for the event (for example, enable-volume-io).

    • action.description - A description of the action.

    • action.event-id - The event ID associated with the action.

    • availability-zone - The Availability Zone of the instance.

    • event.description - A description of the event.

    • event.event-id - The event ID.

    • event.event-type - The event type (for io-enabled: passed | failed; for io-performance: io-performance:degraded | io-performance:severely-degraded | io-performance:stalled).

    • event.not-after - The latest end time for the event.

    • event.not-before - The earliest start time for the event.

    • volume-status.details-name - The cause for volume-status.status (io-enabled | io-performance).

    • volume-status.details-status - The status of volume-status.details-name (for io-enabled: passed | failed; for io-performance: normal | degraded | severely-degraded | stalled).

    • volume-status.status - The status of the volume (ok | impaired | warning | insufficient-data).

  • :max_results (Integer)

    The maximum number of volume results returned by DescribeVolumeStatus in paginated output. When this parameter is used, the request only returns MaxResults results in a single page along with a NextToken response element. The remaining results of the initial request can be seen by sending another request with the returned NextToken value. This value can be between 5 and 1000; if MaxResults is given a value larger than 1000, only 1000 results are returned. If this parameter is not used, then DescribeVolumeStatus returns all results. You cannot specify this parameter and the volume IDs parameter in the same request.

  • :next_token (String)

    The NextToken value to include in a future DescribeVolumeStatus request. When the results of the request exceed MaxResults, this value can be used to retrieve the next page of results. This value is null when there are no more results to return.

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

See Also:

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

Detaches an EBS volume from an instance. Make sure to unmount any file systems on the device within your operating system before detaching the volume. Failure to do so can result in the volume becoming stuck in the busy state while detaching. If this happens, detachment can be delayed indefinitely until you unmount the volume, force detachment, reboot the instance, or all three. If an EBS volume is the root device of an instance, it can't be detached while the instance is running. To detach the root volume, stop the instance first.

When a volume with an AWS Marketplace product code is detached from an instance, the product code is no longer associated with the instance.

For more information, see Detaching an Amazon EBS volume in the Amazon Elastic Compute Cloud User Guide.

Examples:

Request syntax example with placeholder values


volume.detach_from_instance({
  device: "String",
  force: false,
  instance_id: "InstanceId",
  dry_run: false,
})

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.

  • :instance_id (String)

    The ID of the instance. If you are detaching a Multi-Attach enabled volume, you must specify an instance ID.

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

See Also:

#enable_io(options = {}) ⇒ Struct

Enables I/O operations for a volume that had I/O operations disabled because the data on the volume was potentially inconsistent.

Examples:

Request syntax example with placeholder values


volume.enable_io({
  dry_run: false,
})

Options Hash (options):

  • :dry_run (Boolean)

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

Returns:

  • (Struct)

    Returns an empty response.

See Also:

#modify_attribute(options = {}) ⇒ Struct

Modifies a volume attribute.

By default, all I/O operations for the volume are suspended when the data on the volume is determined to be potentially inconsistent, to prevent undetectable, latent data corruption. The I/O access to the volume can be resumed by first enabling I/O access and then checking the data consistency on your volume.

You can change the default behavior to resume I/O operations. We recommend that you change this only for boot volumes or for volumes that are stateless or disposable.

Examples:

Request syntax example with placeholder values


volume.modify_attribute({
  auto_enable_io: {
    value: false,
  },
  dry_run: false,
})

Options Hash (options):

  • :auto_enable_io (Types::AttributeBooleanValue)

    Indicates whether the volume should be auto-enabled for I/O operations.

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

  • (Struct)

    Returns an empty response.

See Also:

#snapshots(options = {}) ⇒ Collection<Snapshot>

Returns a Collection of Snapshot resources. No API requests are made until you call an enumerable method on the collection. Client#describe_snapshots will be called multiple times until every Snapshot has been yielded.

Examples:

Request syntax example with placeholder values


volume.snapshots({
  max_results: 1,
  next_token: "String",
  owner_ids: ["String"],
  restorable_by_user_ids: ["String"],
  snapshot_ids: ["SnapshotId"],
  dry_run: false,
})

Enumerating Snapshot resources.

volume.snapshots.each do |snapshot|
  # yields each snapshot
end

Enumerating Snapshot resources with a limit.

volume.snapshots.limit(10).each do |snapshot|
  # yields at most 10 snapshots
end

Options Hash (options):

  • :max_results (Integer)

    The maximum number of snapshot results returned by DescribeSnapshots in paginated output. When this parameter is used, DescribeSnapshots only returns MaxResults results in a single page along with a NextToken response element. The remaining results of the initial request can be seen by sending another DescribeSnapshots request with the returned NextToken value. This value can be between 5 and 1000; if MaxResults is given a value larger than 1000, only 1000 results are returned. If this parameter is not used, then DescribeSnapshots returns all results. You cannot specify this parameter and the snapshot IDs parameter in the same request.

  • :next_token (String)

    The NextToken value returned from a previous paginated DescribeSnapshots request where MaxResults was used and the results exceeded the value of that parameter. Pagination continues from the end of the previous results that returned the NextToken value. This value is null when there are no more results to return.

  • :owner_ids (Array<String>)

    Scopes the results to snapshots with the specified owners. You can specify a combination of AWS account IDs, self, and amazon.

  • :restorable_by_user_ids (Array<String>)

    The IDs of the AWS accounts that can create volumes from the snapshot.

  • :snapshot_ids (Array<String>)

    The snapshot IDs.

    Default: Describes the snapshots for which you have create volume permissions.

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

See Also: