Class: Aws::AutoScaling::ScalingPolicy
- Inherits:
-
Object
- Object
- Aws::AutoScaling::ScalingPolicy
- Extended by:
- Deprecations
- Defined in:
- lib/aws-sdk-autoscaling/scaling_policy.rb
Defined Under Namespace
Classes: Collection
Read-Only Attributes collapse
-
#adjustment_type ⇒ String
The adjustment type, which specifies how ‘ScalingAdjustment` is interpreted.
-
#alarms ⇒ Array<Types::Alarm>
The CloudWatch alarms related to the policy.
-
#auto_scaling_group_name ⇒ String
The name of the Auto Scaling group.
-
#cooldown ⇒ Integer
The amount of time, in seconds, after a scaling activity completes before any further dynamic scaling activities can start.
-
#estimated_instance_warmup ⇒ Integer
The estimated time, in seconds, until a newly launched instance can contribute to the CloudWatch metrics.
-
#metric_aggregation_type ⇒ String
The aggregation type for the CloudWatch metrics.
-
#min_adjustment_magnitude ⇒ Integer
The minimum number of instances to scale.
-
#min_adjustment_step ⇒ Integer
Available for backward compatibility.
- #name ⇒ String (also: #policy_name)
-
#policy_arn ⇒ String
The Amazon Resource Name (ARN) of the policy.
-
#policy_type ⇒ String
The policy type.
-
#scaling_adjustment ⇒ Integer
The amount by which to scale, based on the specified adjustment type.
-
#step_adjustments ⇒ Array<Types::StepAdjustment>
A set of adjustments that enable you to scale based on the size of the alarm breach.
-
#target_tracking_configuration ⇒ Types::TargetTrackingConfiguration
A target tracking policy.
Actions collapse
Associations collapse
- #group ⇒ AutoScalingGroup?
- #identifiers ⇒ Object deprecated private Deprecated.
Instance Method Summary collapse
- #client ⇒ Client
-
#data ⇒ Types::ScalingPolicy
Returns the data for this ScalingPolicy.
-
#data_loaded? ⇒ Boolean
Returns ‘true` if this resource is loaded.
-
#initialize(*args) ⇒ ScalingPolicy
constructor
A new instance of ScalingPolicy.
-
#load ⇒ self
(also: #reload)
Loads, or reloads #data for the current ScalingPolicy.
-
#wait_until(options = {}, &block) ⇒ Resource
deprecated
Deprecated.
Use [Aws::AutoScaling::Client] #wait_until instead
Constructor Details
#initialize(name, options = {}) ⇒ ScalingPolicy #initialize(options = {}) ⇒ ScalingPolicy
Returns a new instance of ScalingPolicy.
19 20 21 22 23 24 |
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 19 def initialize(*args) = Hash === args.last ? args.pop.dup : {} @name = extract_name(args, ) @data = .delete(:data) @client = .delete(:client) || Client.new() end |
Instance Method Details
#adjustment_type ⇒ String
The adjustment type, which specifies how ‘ScalingAdjustment` is interpreted. Valid values are `ChangeInCapacity`, `ExactCapacity`, and `PercentChangeInCapacity`.
56 57 58 |
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 56 def adjustment_type data[:adjustment_type] end |
#alarms ⇒ Array<Types::Alarm>
The CloudWatch alarms related to the policy.
114 115 116 |
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 114 def alarms data[:alarms] end |
#auto_scaling_group_name ⇒ String
The name of the Auto Scaling group.
36 37 38 |
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 36 def auto_scaling_group_name data[:auto_scaling_group_name] end |
#client ⇒ Client
127 128 129 |
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 127 def client @client end |
#cooldown ⇒ Integer
The amount of time, in seconds, after a scaling activity completes before any further dynamic scaling activities can start.
87 88 89 |
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 87 def cooldown data[:cooldown] end |
#data ⇒ Types::ScalingPolicy
Returns the data for this Aws::AutoScaling::ScalingPolicy. Calls Client#describe_policies if #data_loaded? is ‘false`.
147 148 149 150 |
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 147 def data load unless @data @data end |
#data_loaded? ⇒ Boolean
155 156 157 |
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 155 def data_loaded? !!@data end |
#delete(options = {}) ⇒ EmptyStructure
265 266 267 268 269 |
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 265 def delete( = {}) = .merge(policy_name: @name) resp = @client.delete_policy() resp.data end |
#estimated_instance_warmup ⇒ Integer
The estimated time, in seconds, until a newly launched instance can contribute to the CloudWatch metrics.
108 109 110 |
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 108 def estimated_instance_warmup data[:estimated_instance_warmup] end |
#execute(options = {}) ⇒ EmptyStructure
312 313 314 315 316 |
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 312 def execute( = {}) = .merge(policy_name: @name) resp = @client.execute_policy() resp.data end |
#group ⇒ AutoScalingGroup?
321 322 323 324 325 326 327 328 329 330 |
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 321 def group if data[:auto_scaling_group_name] AutoScalingGroup.new( name: data[:auto_scaling_group_name], client: @client ) else nil end end |
#identifiers ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
334 335 336 |
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 334 def identifiers { name: @name } end |
#load ⇒ self 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
137 138 139 140 141 |
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 137 def load resp = @client.describe_policies(policy_names: [@name]) @data = resp.scaling_policies[0] self end |
#metric_aggregation_type ⇒ String
The aggregation type for the CloudWatch metrics. Valid values are ‘Minimum`, `Maximum`, and `Average`.
101 102 103 |
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 101 def metric_aggregation_type data[:metric_aggregation_type] end |
#min_adjustment_magnitude ⇒ Integer
The minimum number of instances to scale. If the value of ‘AdjustmentType` is `PercentChangeInCapacity`, the scaling policy changes the `DesiredCapacity` of the Auto Scaling group by at least this many instances. Otherwise, the error is `ValidationError`.
72 73 74 |
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 72 def min_adjustment_magnitude data[:min_adjustment_magnitude] end |
#min_adjustment_step ⇒ Integer
Available for backward compatibility. Use ‘MinAdjustmentMagnitude` instead.
63 64 65 |
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 63 def min_adjustment_step data[:min_adjustment_step] end |
#name ⇒ String Also known as: policy_name
29 30 31 |
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 29 def name @name end |
#policy_arn ⇒ String
The Amazon Resource Name (ARN) of the policy.
42 43 44 |
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 42 def policy_arn data[:policy_arn] end |
#policy_type ⇒ String
The policy type. Valid values are ‘SimpleScaling` and `StepScaling`.
48 49 50 |
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 48 def policy_type data[:policy_type] end |
#scaling_adjustment ⇒ Integer
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.
80 81 82 |
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 80 def scaling_adjustment data[:scaling_adjustment] end |
#step_adjustments ⇒ Array<Types::StepAdjustment>
A set of adjustments that enable you to scale based on the size of the alarm breach.
94 95 96 |
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 94 def step_adjustments data[:step_adjustments] end |
#target_tracking_configuration ⇒ Types::TargetTrackingConfiguration
A target tracking policy.
120 121 122 |
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 120 def target_tracking_configuration data[:target_tracking_configuration] end |
#wait_until(options = {}, &block) ⇒ Resource
Use [Aws::AutoScaling::Client] #wait_until instead
The waiting operation is performed on a copy. The original resource remains unchanged
Waiter polls an API operation until a resource enters a desired state.
## Basic Usage
Waiter will polls until it is successful, it fails by entering a terminal state, or until a maximum number of attempts are made.
# polls in a loop until condition is true
resource.wait_until() {|resource| condition}
## Example
instance.wait_until(max_attempts:10, delay:5) {|instance| instance.state.name == 'running' }
## Configuration
You can configure the maximum number of polling attempts, and the delay (in seconds) between each polling attempt. The waiting condition is set by passing a block to #wait_until:
# poll for ~25 seconds
resource.wait_until(max_attempts:5,delay:5) {|resource|...}
## Callbacks
You can be notified before each polling attempt and before each delay. If you throw ‘:success` or `:failure` from these callbacks, it will terminate the waiter.
started_at = Time.now
# poll for 1 hour, instead of a number of attempts
proc = Proc.new do |attempts, response|
throw :failure if Time.now - started_at > 3600
end
# disable max attempts
instance.wait_until(before_wait:proc, max_attempts:nil) {...}
## Handling Errors
When a waiter is successful, it returns the Resource. When a waiter fails, it raises an error.
begin
resource.wait_until(...)
rescue Aws::Waiters::Errors::WaiterFailed
# resource did not enter the desired state in time
end
attempts attempt in seconds invoked before each attempt invoked before each wait
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/aws-sdk-autoscaling/scaling_policy.rb', line 237 def wait_until( = {}, &block) self_copy = self.dup attempts = 0 [:max_attempts] = 10 unless .key?(:max_attempts) [:delay] ||= 10 [:poller] = Proc.new do attempts += 1 if block.call(self_copy) [:success, self_copy] else self_copy.reload unless attempts == [:max_attempts] :retry end end Aws::Waiters::Waiter.new().wait({}) end |