Class: Aws::AutoScaling::ScalingPolicy

Inherits:
Object
  • Object
show all
Extended by:
Deprecations
Defined in:
lib/aws-sdk-autoscaling/scaling_policy.rb

Defined Under Namespace

Classes: Collection

Read-Only Attributes collapse

Actions collapse

Associations collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ ScalingPolicy #initialize(options = {}) ⇒ ScalingPolicy

Returns a new instance of ScalingPolicy.

Overloads:

  • #initialize(name, options = {}) ⇒ ScalingPolicy

    Parameters:

    • name (String)

    Options Hash (options):

  • #initialize(options = {}) ⇒ ScalingPolicy

    Options Hash (options):

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


22
23
24
25
26
27
28
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 22

def initialize(*args)
  options = Hash === args.last ? args.pop.dup : {}
  @name = extract_name(args, options)
  @data = options.delete(:data)
  @client = options.delete(:client) || Client.new(options)
  @waiter_block_warned = false
end

Instance Method Details

#adjustment_typeString

Specifies how the scaling adjustment is interpreted (for example, an absolute number or a percentage). The valid values are ‘ChangeInCapacity`, `ExactCapacity`, and `PercentChangeInCapacity`.

Returns:

  • (String)


77
78
79
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 77

def adjustment_type
  data[:adjustment_type]
end

#alarmsArray<Types::Alarm>

The CloudWatch alarms related to the policy.

Returns:



132
133
134
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 132

def alarms
  data[:alarms]
end

#auto_scaling_group_nameString

The name of the Auto Scaling group.

Returns:

  • (String)


40
41
42
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 40

def auto_scaling_group_name
  data[:auto_scaling_group_name]
end

#clientClient

Returns:



158
159
160
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 158

def client
  @client
end

#cooldownInteger

The duration of the policy’s cooldown period, in seconds.

Returns:

  • (Integer)


105
106
107
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 105

def cooldown
  data[:cooldown]
end

#dataTypes::ScalingPolicy

Returns the data for this Aws::AutoScaling::ScalingPolicy. Calls Client#describe_policies if #data_loaded? is ‘false`.

Returns:



180
181
182
183
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 180

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.



188
189
190
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 188

def data_loaded?
  !!@data
end

#delete(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


scaling_policy.delete({
  auto_scaling_group_name: "XmlStringMaxLen255",
})

Parameters:

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

    ({})

Options Hash (options):

  • :auto_scaling_group_name (String)

    The name of the Auto Scaling group.

Returns:

  • (EmptyStructure)


302
303
304
305
306
307
308
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 302

def delete(options = {})
  options = options.merge(policy_name: @name)
  resp = Aws::Plugins::UserAgent.feature('resource') do
    @client.delete_policy(options)
  end
  resp.data
end

#enabledBoolean

Indicates whether the policy is enabled (‘true`) or disabled (`false`).

Returns:

  • (Boolean)


145
146
147
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 145

def enabled
  data[:enabled]
end

#estimated_instance_warmupInteger

The estimated time, in seconds, until a newly launched instance can contribute to the CloudWatch metrics.

Returns:

  • (Integer)


126
127
128
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 126

def estimated_instance_warmup
  data[:estimated_instance_warmup]
end

#execute(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


scaling_policy.execute({
  auto_scaling_group_name: "XmlStringMaxLen255",
  honor_cooldown: false,
  metric_value: 1.0,
  breach_threshold: 1.0,
})

Parameters:

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

    ({})

Options Hash (options):

  • :auto_scaling_group_name (String)

    The name of the Auto Scaling group.

  • :honor_cooldown (Boolean)

    Indicates whether Amazon EC2 Auto Scaling waits for the cooldown period to complete before executing the policy.

    Valid only if the policy type is ‘SimpleScaling`. For more information, see [Scaling cooldowns for Amazon EC2 Auto Scaling] in the *Amazon EC2 Auto Scaling User Guide*.

    [1]: docs.aws.amazon.com/autoscaling/ec2/userguide/Cooldown.html

  • :metric_value (Float)

    The metric value to compare to ‘BreachThreshold`. This enables you to execute a policy of type `StepScaling` and determine which step adjustment to use. For example, if the breach threshold is 50 and you want to use a step adjustment with a lower bound of 0 and an upper bound of 10, you can set the metric value to 59.

    If you specify a metric value that doesn’t correspond to a step adjustment for the policy, the call returns an error.

    Required if the policy type is ‘StepScaling` and not supported otherwise.

  • :breach_threshold (Float)

    The breach threshold for the alarm.

    Required if the policy type is ‘StepScaling` and not supported otherwise.

Returns:

  • (EmptyStructure)


350
351
352
353
354
355
356
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 350

def execute(options = {})
  options = options.merge(policy_name: @name)
  resp = Aws::Plugins::UserAgent.feature('resource') do
    @client.execute_policy(options)
  end
  resp.data
end

#groupAutoScalingGroup?

Returns:



361
362
363
364
365
366
367
368
369
370
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 361

def group
  if data[:auto_scaling_group_name]
    AutoScalingGroup.new(
      name: data[:auto_scaling_group_name],
      client: @client
    )
  else
    nil
  end
end

#identifiersObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Deprecated.


374
375
376
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 374

def identifiers
  { name: @name }
end

#loadself Also known as: reload

Loads, or reloads #data for the current Aws::AutoScaling::ScalingPolicy. Returns ‘self` making it possible to chain methods.

scaling_policy.reload.data

Returns:

  • (self)


168
169
170
171
172
173
174
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 168

def load
  resp = Aws::Plugins::UserAgent.feature('resource') do
    @client.describe_policies(policy_names: [@name])
  end
  @data = resp.scaling_policies[0]
  self
end

#metric_aggregation_typeString

The aggregation type for the CloudWatch metrics. The valid values are ‘Minimum`, `Maximum`, and `Average`.

Returns:

  • (String)


119
120
121
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 119

def metric_aggregation_type
  data[:metric_aggregation_type]
end

#min_adjustment_magnitudeInteger

The minimum value to scale by when the adjustment type is ‘PercentChangeInCapacity`.

Returns:

  • (Integer)


91
92
93
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 91

def min_adjustment_magnitude
  data[:min_adjustment_magnitude]
end

#min_adjustment_stepInteger

Available for backward compatibility. Use ‘MinAdjustmentMagnitude` instead.

Returns:

  • (Integer)


84
85
86
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 84

def min_adjustment_step
  data[:min_adjustment_step]
end

#nameString Also known as: policy_name

Returns:

  • (String)


33
34
35
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 33

def name
  @name
end

#policy_arnString

The Amazon Resource Name (ARN) of the policy.

Returns:

  • (String)


46
47
48
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 46

def policy_arn
  data[:policy_arn]
end

#policy_typeString

One of the following policy types:

  • ‘TargetTrackingScaling`

  • ‘StepScaling`

  • ‘SimpleScaling` (default)

  • ‘PredictiveScaling`

For more information, see [Target tracking scaling policies] and

Step and simple scaling policies][2

in the *Amazon EC2 Auto Scaling

User Guide*.

[1]: docs.aws.amazon.com/autoscaling/ec2/userguide/as-scaling-target-tracking.html [2]: docs.aws.amazon.com/autoscaling/ec2/userguide/as-scaling-simple-step.html

Returns:

  • (String)


69
70
71
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 69

def policy_type
  data[:policy_type]
end

#predictive_scaling_configurationTypes::PredictiveScalingConfiguration

A predictive scaling policy.



151
152
153
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 151

def predictive_scaling_configuration
  data[:predictive_scaling_configuration]
end

#scaling_adjustmentInteger

The amount by which to scale, based on the specified adjustment type. A positive value adds to the current capacity while a negative number removes from the current capacity.

Returns:

  • (Integer)


99
100
101
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 99

def scaling_adjustment
  data[:scaling_adjustment]
end

#step_adjustmentsArray<Types::StepAdjustment>

A set of adjustments that enable you to scale based on the size of the alarm breach.

Returns:



112
113
114
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 112

def step_adjustments
  data[:step_adjustments]
end

#target_tracking_configurationTypes::TargetTrackingConfiguration

A target tracking scaling policy.



138
139
140
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 138

def target_tracking_configuration
  data[:target_tracking_configuration]
end

#wait_until(options = {}) {|resource| ... } ⇒ Resource

Deprecated.

Use [Aws::AutoScaling::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



272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 272

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.feature('resource') do
    Aws::Waiters::Waiter.new(options).wait({})
  end
end