Class: AWS::AutoScaling::ScalingPolicy

Inherits:
Core::Resource show all
Includes:
ScalingPolicyOptions
Defined in:
lib/aws/auto_scaling/scaling_policy.rb

Instance Attribute Summary collapse

Attributes included from Core::Model

#config

Instance Method Summary collapse

Methods inherited from Core::Resource

attribute_providers, attribute_providers_for, attributes, #attributes_from_response, define_attribute_type, #eql?, #inspect, new_from

Methods included from Core::Cacheable

included, #retrieve_attribute

Methods included from Core::Model

#client, #config_prefix, #inspect

Constructor Details

#initialize(auto_scaling_group, policy_name, options = {}) ⇒ ScalingPolicy

Returns a new instance of ScalingPolicy.



21
22
23
24
25
# File 'lib/aws/auto_scaling/scaling_policy.rb', line 21

def initialize auto_scaling_group, policy_name, options = {}
  @group = auto_scaling_group
  @name = policy_name
  super
end

Instance Attribute Details

#groupGroup (readonly) Also known as: auto_scaling_group

Returns:



28
29
30
# File 'lib/aws/auto_scaling/scaling_policy.rb', line 28

def group
  @group
end

#nameString (readonly)

Returns:

  • (String)


33
34
35
# File 'lib/aws/auto_scaling/scaling_policy.rb', line 33

def name
  @name
end

Instance Method Details

#deletenil

Deletes this scaling policy.

Returns:

  • (nil)


93
94
95
96
97
98
99
# File 'lib/aws/auto_scaling/scaling_policy.rb', line 93

def delete
  client_opts = {}
  client_opts[:auto_scaling_group_name] = group.name
  client_opts[:policy_name] = name
  client.delete_policy(client_opts)
  nil
end

#execute(options = {}) ⇒ nil

Runs this policy against it’s Auto Scaling group.

Parameters:

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

Options Hash (options):

  • :honor_cooldown (Boolean) — default: false

    Set to true if you want Auto Scaling to reject this request when the Auto Scaling group is in cooldown.

Returns:

  • (nil)

Raises:

  • (Errors::ScalingActivityInProgress)


82
83
84
85
86
87
88
89
# File 'lib/aws/auto_scaling/scaling_policy.rb', line 82

def execute options = {}
  client_opts = {}
  client_opts[:auto_scaling_group_name] = group.name
  client_opts[:policy_name] = name
  client_opts[:honor_cooldown] = options[:honor_cooldown] == true
  client.execute_policy(client_opts)
  nil
end

#exists?Boolean

Returns true if the policy exists.

Returns:

  • (Boolean)

    Returns true if the policy exists.



102
103
104
105
106
107
108
# File 'lib/aws/auto_scaling/scaling_policy.rb', line 102

def exists?
  client_opts = {}
  client_opts[:auto_scaling_group_name] = group.name
  client_opts[:policy_names] = [name]
  resp = client.describe_policies(client_opts)
  !resp.scaling_policies.empty?
end

#update(options = {}) ⇒ nil Also known as: put

Updates this scaling policy.

Parameters:

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

Options Hash (options):

  • :adjustment_type (required, String)

    Specifies whether the adjustment is an absolute number or a percentage of the current capacity. Valid values are:

    • ‘ChangeInCapacity’

    • ‘ExactCapacity’

    • ‘PercentChangeInCapacity’

  • :scaling_adjustment (required, Integer)

    The number of instances by which to scale. :adjustment_type determines the interpretation of this umber (e.g., as an absolute number or as a percentage of the existing Auto Scaling group size). A positive increment adds to the current capacity and a negative value removes from the current capacity.

  • :cooldown (Integer)

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

Returns:

  • (nil)


62
63
64
65
66
67
# File 'lib/aws/auto_scaling/scaling_policy.rb', line 62

def update options = {}
  client_opts = scaling_policy_options(group, name, options)
  resp = client.put_scaling_policy(client_opts)
  static_attributes[:arn] = resp.policy_arn
  nil
end