Class: Aws::EC2::Snapshot

Inherits:
Object
  • Object
show all
Defined in:
gems/aws-sdk-ec2/lib/aws-sdk-ec2/snapshot.rb

Defined Under Namespace

Classes: Collection

Read-Only Attributes collapse

Actions collapse

Associations collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Snapshot.

Overloads:

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

    Parameters:

    • id (String)

    Options Hash (options):

  • #initialize(options = {}) ⇒ Snapshot

    Options Hash (options):

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


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

#associated_kms_keys ⇒ Array<Types::AssociatedKmsKey>

The additional KMS keys that are associated with the snapshot.

Returns:



144
145
146
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/snapshot.rb', line 144

def associated_kms_keys
  data[:associated_kms_keys]
end

#availability_zone ⇒ String

The Availability Zone or Local Zone of the snapshot. For example, us-west-1a (Availability Zone) or us-west-2-lax-1a (Local Zone).

Returns:

  • (String)


90
91
92
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/snapshot.rb', line 90

def availability_zone
  data[:availability_zone]
end

#client ⇒ Client

Returns:



230
231
232
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/snapshot.rb', line 230

def client
  @client
end

#completion_duration_minutes ⇒ Integer

Only for snapshot copies created with time-based snapshot copy operations.

The completion duration requested for the time-based snapshot copy operation.

Returns:

  • (Integer)


122
123
124
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/snapshot.rb', line 122

def completion_duration_minutes
  data[:completion_duration_minutes]
end

#completion_time ⇒ Time

The time stamp when the snapshot was completed.

Returns:

  • (Time)


128
129
130
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/snapshot.rb', line 128

def completion_time
  data[:completion_time]
end

#copy(options = {}) ⇒ Types::CopySnapshotResult

Examples:

Request syntax with placeholder values


snapshot.copy({
  description: "String",
  destination_outpost_arn: "String",
  destination_region: "String",
  encrypted: false,
  kms_key_id: "KmsKeyId",
  presigned_url: "CopySnapshotRequestPSU",
  source_region: "String", # required
  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, fca-policy, 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, ipam-internet-registry-association, secondary-interface, secondary-network, secondary-subnet, capacity-manager-data-export, vpn-concentrator, ipam-pool-allocation, capacity-reservation-cancellation-quote, application-status-check, capacity-reservation-modification-quote, metric-category
      tags: [
        {
          key: "String",
          value: "String",
        },
      ],
    },
  ],
  completion_duration_minutes: 1,
  destination_availability_zone: "String",
  dry_run: false,
})

Parameters:

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

    ({})

Options Hash (options):

  • :description (String) —

    A description for the EBS snapshot.

  • :destination_outpost_arn (String) —

    The Amazon Resource Name (ARN) of the Outpost to which to copy the snapshot.

    Only supported when copying a snapshot to an Outpost.

    For more information, see Copy snapshots from an Amazon Web Services Region to an Outpost in the Amazon EBS User Guide.

  • :destination_region (String) —

    Deprecated.

  • :encrypted (Boolean) —

    To encrypt a copy of an unencrypted snapshot if encryption by default is not enabled, enable encryption using this parameter. Otherwise, omit this parameter. Copies of encrypted snapshots are encrypted, even if you omit this parameter and encryption by default is not enabled. You cannot set this parameter to false. For more information, see Amazon EBS encryption in the Amazon EBS User Guide.

  • :kms_key_id (String) —

    The identifier of the KMS key to use for Amazon EBS encryption. If this parameter is not specified, your KMS key for Amazon EBS is used. If KmsKeyId is specified, the encrypted state must be true.

    You can specify the KMS key using any of the following:

    • Key ID. For example, 1234abcd-12ab-34cd-56ef-1234567890ab.

    • Key alias. For example, alias/ExampleAlias.

    • Key ARN. For example, arn:aws:kms:us-east-1:012345678910:key/1234abcd-12ab-34cd-56ef-1234567890ab.

    • Alias ARN. For example, arn:aws:kms:us-east-1:012345678910:alias/ExampleAlias.

    Amazon Web Services authenticates the KMS key asynchronously. Therefore, if you specify an ID, alias, or ARN that is not valid, the action can appear to complete, but eventually fails.

  • :presigned_url (String) —

    Deprecated.

  • :source_region (required, String) —

    The ID of the Region that contains the snapshot to be copied.

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

    The tags to apply to the new snapshot.

  • :completion_duration_minutes (Integer) —

    Not supported when copying snapshots to or from Local Zones or Outposts.

    Specify a completion duration, in 15 minute increments, to initiate a time-based snapshot copy. Time-based snapshot copy operations complete within the specified duration. For more information, see Time-based copies.

    If you do not specify a value, the snapshot copy operation is completed on a best-effort basis.

  • :destination_availability_zone (String) —

    The Local Zone, for example, cn-north-1-pkx-1a to which to copy the snapshot.

    Only supported when copying a snapshot to a Local Zone.

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



496
497
498
499
500
501
502
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/snapshot.rb', line 496

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

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

Examples:

Request syntax with placeholder values


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



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

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

#data ⇒ Types::Snapshot

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

Returns:



252
253
254
255
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/snapshot.rb', line 252

def data
  load unless @data
  @data
end

#data_encryption_key_id ⇒ String

The data encryption key identifier for the snapshot. This value is a unique identifier that corresponds to the data encryption key that was used to encrypt the original volume or snapshot copy. Because data encryption keys are inherited by volumes created from snapshots, and vice versa, if snapshots share the same data encryption key identifier, then they belong to the same volume/snapshot lineage. This parameter is only returned by DescribeSnapshots.

Returns:

  • (String)


223
224
225
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/snapshot.rb', line 223

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



260
261
262
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/snapshot.rb', line 260

def data_loaded?
  !!@data
end

#delete(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


snapshot.delete({
  dry_run: false,
})

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.

Returns:

  • (EmptyStructure)


602
603
604
605
606
607
608
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/snapshot.rb', line 602

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

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

Examples:

Request syntax with placeholder values


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



573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/snapshot.rb', line 573

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

Examples:

Request syntax with placeholder values


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

Parameters:

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

    ({})

Options Hash (options):

  • :attribute (required, String) —

    The snapshot attribute you would like to view.

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



625
626
627
628
629
630
631
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/snapshot.rb', line 625

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

#description ⇒ String

The description for the snapshot.

Returns:

  • (String)


192
193
194
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/snapshot.rb', line 192

def description
  data[:description]
end

#encrypted ⇒ Boolean

Indicates whether the snapshot is encrypted.

Returns:

  • (Boolean)


204
205
206
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/snapshot.rb', line 204

def encrypted
  data[:encrypted]
end

#full_snapshot_size_in_bytes ⇒ Integer

The full size of the snapshot, in bytes.

This is not the incremental size of the snapshot. This is the full snapshot size and represents the size of all the blocks that were written to the source volume at the time the snapshot was created.

Returns:

  • (Integer)


138
139
140
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/snapshot.rb', line 138

def full_snapshot_size_in_bytes
  data[:full_snapshot_size_in_bytes]
end

#id ⇒ String Also known as: snapshot_id

Returns:

  • (String)


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

def id
  @id
end

#kms_key_id ⇒ String

The Amazon Resource Name (ARN) of the KMS key that was used to protect the volume encryption key for the parent volume.

Returns:

  • (String)


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

def kms_key_id
  data[:kms_key_id]
end

#load ⇒ self Also known as: reload

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

snapshot.reload.data

Returns:

  • (self)


240
241
242
243
244
245
246
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/snapshot.rb', line 240

def load
  resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
    @client.describe_snapshots(snapshot_ids: [@id])
  end
  @data = resp.snapshots[0]
  self
end

#modify_attribute(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


snapshot.modify_attribute({
  attribute: "productCodes", # accepts productCodes, createVolumePermission
  create_volume_permission: {
    add: [
      {
        user_id: "String",
        group: "all", # accepts all
      },
    ],
    remove: [
      {
        user_id: "String",
        group: "all", # accepts all
      },
    ],
  },
  group_names: ["SecurityGroupName"],
  operation_type: "add", # accepts add, remove
  user_ids: ["String"],
  dry_run: false,
})

Parameters:

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

    ({})

Options Hash (options):

  • :attribute (String) —

    The snapshot attribute to modify. Only volume creation permissions can be modified.

  • :create_volume_permission (Types::CreateVolumePermissionModifications) —

    A JSON representation of the snapshot attribute modification.

  • :group_names (Array<String>) —

    The group to modify for the snapshot.

  • :operation_type (String) —

    The type of operation to perform to the attribute.

  • :user_ids (Array<String>) —

    The account ID to modify for the snapshot.

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

  • (EmptyStructure)


674
675
676
677
678
679
680
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/snapshot.rb', line 674

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

#outpost_arn ⇒ String

The ARN of the Outpost on which the snapshot is stored. For more information, see Amazon EBS local snapshots on Outposts in the Amazon EBS User Guide.

Returns:

  • (String)


54
55
56
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/snapshot.rb', line 54

def outpost_arn
  data[:outpost_arn]
end

#owner_alias ⇒ String

The Amazon Web Services owner alias, from an Amazon-maintained list (amazon). This is not the user-configured Amazon Web Services account alias set using the IAM console.

Returns:

  • (String)


42
43
44
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/snapshot.rb', line 42

def owner_alias
  data[:owner_alias]
end

#owner_id ⇒ String

The ID of the Amazon Web Services account that owns the EBS snapshot.

Returns:

  • (String)


186
187
188
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/snapshot.rb', line 186

def owner_id
  data[:owner_id]
end

#progress ⇒ String

The progress of the snapshot, as a percentage.

Returns:

  • (String)


180
181
182
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/snapshot.rb', line 180

def progress
  data[:progress]
end

#reset_attribute(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


snapshot.reset_attribute({
  attribute: "productCodes", # required, accepts productCodes, createVolumePermission
  dry_run: false,
})

Parameters:

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

    ({})

Options Hash (options):

  • :attribute (required, String) —

    The attribute to reset. Currently, only the attribute for permission to create volumes can be reset.

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

  • (EmptyStructure)


698
699
700
701
702
703
704
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/snapshot.rb', line 698

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

#restore_expiry_time ⇒ Time

Only for archived snapshots that are temporarily restored. Indicates the date and time when a temporarily restored snapshot will be automatically re-archived.

Returns:

  • (Time)


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

def restore_expiry_time
  data[:restore_expiry_time]
end

#sse_type ⇒ String

Reserved for future use.

Returns:

  • (String)


83
84
85
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/snapshot.rb', line 83

def sse_type
  data[:sse_type]
end

#start_time ⇒ Time

The time stamp when the snapshot was initiated.

Returns:

  • (Time)


174
175
176
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/snapshot.rb', line 174

def start_time
  data[:start_time]
end

#state ⇒ String

The snapshot state.

Returns:

  • (String)


158
159
160
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/snapshot.rb', line 158

def state
  data[:state]
end

#state_message ⇒ String

Encrypted Amazon EBS snapshots are copied asynchronously. If a snapshot copy operation fails (for example, if the proper KMS permissions are not obtained) this field displays error state details to help you diagnose why the error occurred. This parameter is only returned by DescribeSnapshots.

Returns:

  • (String)


168
169
170
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/snapshot.rb', line 168

def state_message
  data[:state_message]
end

#storage_tier ⇒ String

The storage tier in which the snapshot is stored. standard indicates that the snapshot is stored in the standard snapshot storage tier and that it is ready for use. archive indicates that the snapshot is currently archived and that it must be restored before it can be used.

Returns:

  • (String)


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

def storage_tier
  data[:storage_tier]
end

#tags ⇒ Array<Types::Tag>

Any tags assigned to the snapshot.

Returns:



60
61
62
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/snapshot.rb', line 60

def tags
  data[:tags]
end

#transfer_type ⇒ String

Only for snapshot copies.

Indicates whether the snapshot copy was created with a standard or time-based snapshot copy operation. Time-based snapshot copy operations complete within the completion duration specified in the request. Standard snapshot copy operations are completed on a best-effort basis.

  • standard - The snapshot copy was created with a standard snapshot copy operation.

  • time-based - The snapshot copy was created with a time-based snapshot copy operation.

Returns:

  • (String)


110
111
112
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/snapshot.rb', line 110

def transfer_type
  data[:transfer_type]
end

#volume ⇒ Volume?

Returns:



709
710
711
712
713
714
715
716
717
718
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/snapshot.rb', line 709

def volume
  if data[:volume_id]
    Volume.new(
      id: data[:volume_id],
      client: @client
    )
  else
    nil
  end
end

#volume_id ⇒ String

The ID of the volume that was used to create the snapshot. Snapshots created by a copy snapshot operation have an arbitrary volume ID that you should not use for any purpose.

Returns:

  • (String)


152
153
154
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/snapshot.rb', line 152

def volume_id
  data[:volume_id]
end

#volume_size ⇒ Integer

The size of the volume, in GiB.

Returns:

  • (Integer)


198
199
200
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/snapshot.rb', line 198

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



364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/snapshot.rb', line 364

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_completed(options = {}, &block) ⇒ Snapshot

Parameters:

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

    ({})

Options Hash (options):

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

Returns:



270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'gems/aws-sdk-ec2/lib/aws-sdk-ec2/snapshot.rb', line 270

def wait_until_completed(options = {}, &block)
  options, params = separate_params_and_options(options)
  waiter = Waiters::SnapshotCompleted.new(options)
  yield_waiter_and_warn(waiter, &block) if block_given?
  resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
    waiter.wait(params.merge(snapshot_ids: [@id]))
  end
  Snapshot.new({
    id: @id,
    data: resp.data.snapshots[0],
    client: @client
  })
end