Class: Aws::AutoScaling::ScalingPolicy
- Inherits:
-
Object
- Object
- Aws::AutoScaling::ScalingPolicy
- Defined in:
- gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb
Defined Under Namespace
Classes: Collection
Read-Only Attributes collapse
-
#adjustment_type ⇒ String
Specifies how the scaling adjustment is interpreted (for example, an absolute number or a percentage).
-
#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 duration of the policy's cooldown period, in seconds.
-
#enabled ⇒ Boolean
Indicates whether the policy is enabled (
true
) or disabled (false
). -
#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 value to scale by when the adjustment type is
PercentChangeInCapacity
. -
#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
One of the following policy types:.
-
#predictive_scaling_configuration ⇒ Types::PredictiveScalingConfiguration
A predictive scaling policy.
-
#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 scaling policy.
Actions collapse
Associations collapse
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 = {}) {|resource| ... } ⇒ 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.
22 23 24 25 26 27 28 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 22 def initialize(*args) = Hash === args.last ? args.pop.dup : {} @name = extract_name(args, ) @data = .delete(:data) @client = .delete(:client) || Client.new() @waiter_block_warned = false end |
Instance Method Details
#adjustment_type ⇒ String
Specifies how the scaling adjustment is interpreted (for example, an
absolute number or a percentage). The valid values are
ChangeInCapacity
, ExactCapacity
, and PercentChangeInCapacity
.
77 78 79 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 77 def adjustment_type data[:adjustment_type] end |
#alarms ⇒ Array<Types::Alarm>
The CloudWatch alarms related to the policy.
132 133 134 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 132 def alarms data[:alarms] end |
#auto_scaling_group_name ⇒ String
The name of the Auto Scaling group.
40 41 42 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 40 def auto_scaling_group_name data[:auto_scaling_group_name] end |
#client ⇒ Client
158 159 160 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 158 def client @client end |
#cooldown ⇒ Integer
The duration of the policy's cooldown period, in seconds.
105 106 107 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 105 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
.
180 181 182 183 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 180 def data load unless @data @data end |
#data_loaded? ⇒ Boolean
188 189 190 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 188 def data_loaded? !!@data end |
#delete(options = {}) ⇒ EmptyStructure
302 303 304 305 306 307 308 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 302 def delete( = {}) = .merge(policy_name: @name) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.delete_policy() end resp.data end |
#enabled ⇒ Boolean
Indicates whether the policy is enabled (true
) or disabled
(false
).
145 146 147 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 145 def enabled data[:enabled] end |
#estimated_instance_warmup ⇒ Integer
The estimated time, in seconds, until a newly launched instance can contribute to the CloudWatch metrics.
126 127 128 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 126 def estimated_instance_warmup data[:estimated_instance_warmup] end |
#execute(options = {}) ⇒ EmptyStructure
350 351 352 353 354 355 356 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 350 def execute( = {}) = .merge(policy_name: @name) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.execute_policy() end resp.data end |
#group ⇒ AutoScalingGroup?
361 362 363 364 365 366 367 368 369 370 |
# File 'gems/aws-sdk-autoscaling/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 |
#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
168 169 170 171 172 173 174 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 168 def load resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.describe_policies(policy_names: [@name]) end @data = resp.scaling_policies[0] self end |
#metric_aggregation_type ⇒ String
The aggregation type for the CloudWatch metrics. The valid values are
Minimum
, Maximum
, and Average
.
119 120 121 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 119 def metric_aggregation_type data[:metric_aggregation_type] end |
#min_adjustment_magnitude ⇒ Integer
The minimum value to scale by when the adjustment type is
PercentChangeInCapacity
.
91 92 93 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 91 def min_adjustment_magnitude data[:min_adjustment_magnitude] end |
#min_adjustment_step ⇒ Integer
Available for backward compatibility. Use MinAdjustmentMagnitude
instead.
84 85 86 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 84 def min_adjustment_step data[:min_adjustment_step] end |
#name ⇒ String Also known as: policy_name
33 34 35 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 33 def name @name end |
#policy_arn ⇒ String
The Amazon Resource Name (ARN) of the policy.
46 47 48 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 46 def policy_arn data[:policy_arn] end |
#policy_type ⇒ String
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 in the Amazon EC2 Auto Scaling User Guide.
69 70 71 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 69 def policy_type data[:policy_type] end |
#predictive_scaling_configuration ⇒ Types::PredictiveScalingConfiguration
A predictive scaling policy.
151 152 153 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 151 def predictive_scaling_configuration data[:predictive_scaling_configuration] 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.
99 100 101 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 99 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.
112 113 114 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 112 def step_adjustments data[:step_adjustments] end |
#target_tracking_configuration ⇒ Types::TargetTrackingConfiguration
A target tracking scaling policy.
138 139 140 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 138 def target_tracking_configuration data[:target_tracking_configuration] end |
#wait_until(options = {}) {|resource| ... } ⇒ 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) 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
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 272 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::Plugins::UserAgent.metric('RESOURCE_MODEL') do Aws::Waiters::Waiter.new().wait({}) end end |