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

Class: Aws::AutoScaling::ScalingPolicy

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

Defined Under Namespace

Classes: Collection

Actions collapse

Associations collapse

Read-Only Attributes 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)


19
20
21
22
23
24
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 19

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)
end

Instance Method Details

#adjustment_typeString

The adjustment type, which specifies how ScalingAdjustment is interpreted. Valid values are ChangeInCapacity, ExactCapacity, and PercentChangeInCapacity.

Returns:

  • (String)


57
58
59
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 57

def adjustment_type
  data.adjustment_type
end

#alarmsArray<Types::Alarm>

The CloudWatch alarms related to the policy.

Returns:



115
116
117
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 115

def alarms
  data.alarms
end

#auto_scaling_group_nameString

The name of the Auto Scaling group associated with this scaling policy.

Returns:

  • (String)


37
38
39
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 37

def auto_scaling_group_name
  data.auto_scaling_group_name
end

#clientClient

Returns:



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

def client
  @client
end

#cooldownInteger

The amount of time, in seconds, after a scaling activity completes before any further trigger-related scaling activities can start.

Returns:

  • (Integer)


88
89
90
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 88

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:



148
149
150
151
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 148

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.



156
157
158
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 156

def data_loaded?
  !!@data
end

#delete(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


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

Parameters:

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

    ({})

Options Hash (options):

  • :auto_scaling_group_name (String)

    The name of the Auto Scaling group.

Returns:

  • (EmptyStructure)


171
172
173
174
175
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 171

def delete(options = {})
  options = options.merge(policy_name: @name)
  resp = @client.delete_policy(options)
  resp.data
end

#estimated_instance_warmupInteger

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

Returns:

  • (Integer)


109
110
111
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 109

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: "ResourceName",
  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 or Amazon Resource Name (ARN) of the Auto Scaling group.

  • :honor_cooldown (Boolean)

    If this parameter is true, Auto Scaling waits for the cooldown period to complete before executing the policy. Otherwise, Auto Scaling executes the policy without waiting for the cooldown period to complete.

    This parameter is not supported if the policy type is StepScaling.

    For more information, see Auto Scaling Cooldowns in the Auto Scaling User Guide.

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

    This parameter is required if the policy type is StepScaling and not supported otherwise.

  • :breach_threshold (Float)

    The breach threshold for the alarm.

    This parameter is required if the policy type is StepScaling and not supported otherwise.

Returns:

  • (EmptyStructure)


220
221
222
223
224
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 220

def execute(options = {})
  options = options.merge(policy_name: @name)
  resp = @client.execute_policy(options)
  resp.data
end

#groupAutoScalingGroup?

Returns:



229
230
231
232
233
234
235
236
237
238
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 229

def group
  if data.auto_scaling_group_name
    AutoScalingGroup.new(
      name: data.auto_scaling_group_name,
      client: @client
    )
  else
    nil
  end
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)


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

def load
  resp = @client.describe_policies(policy_names: [@name])
  @data = resp.scaling_policies[0]
  self
end

#metric_aggregation_typeString

The aggregation type for the CloudWatch metrics. Valid values are Minimum, Maximum, and Average.

Returns:

  • (String)


102
103
104
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 102

def metric_aggregation_type
  data.metric_aggregation_type
end

#min_adjustment_magnitudeInteger

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.

Returns:

  • (Integer)


73
74
75
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 73

def min_adjustment_magnitude
  data.min_adjustment_magnitude
end

#min_adjustment_stepInteger

Available for backward compatibility. Use MinAdjustmentMagnitude instead.

Returns:

  • (Integer)


64
65
66
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 64

def min_adjustment_step
  data.min_adjustment_step
end

#nameString Also known as: policy_name

Returns:

  • (String)


29
30
31
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 29

def name
  @name
end

#policy_arnString

The Amazon Resource Name (ARN) of the policy.

Returns:

  • (String)


43
44
45
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 43

def policy_arn
  data.policy_arn
end

#policy_typeString

The policy type. Valid values are SimpleScaling and StepScaling.

Returns:

  • (String)


49
50
51
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 49

def policy_type
  data.policy_type
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)


81
82
83
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 81

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:



95
96
97
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 95

def step_adjustments
  data.step_adjustments
end

#target_tracking_configurationTypes::TargetTrackingConfiguration

A target tracking policy.



121
122
123
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/scaling_policy.rb', line 121

def target_tracking_configuration
  data.target_tracking_configuration
end