Class: Aws::AutoScaling::AutoScalingGroup

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

Defined Under Namespace

Classes: Collection

Actions collapse

Associations collapse

Read-Only Attributes collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of AutoScalingGroup.

Overloads:

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

    Parameters:

    • name (String)

    Options Hash (options):

  • #initialize(options = {}) ⇒ AutoScalingGroup

    Options Hash (options):

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


22
23
24
25
26
27
28
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.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

#activities(options = {}) ⇒ Activity::Collection

Examples:

Request syntax with placeholder values


activities = auto_scaling_group.activities({
  activity_ids: ["XmlString"],
})

Parameters:

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

    ({})

Options Hash (options):

  • :activity_ids (Array<String>)

    The activity IDs of the desired scaling activities. You can specify up to 50 IDs. If you omit this parameter, all activities for the past six weeks are described. If unknown activities are requested, they are ignored with no error. If you specify an Auto Scaling group, the results are limited to that group.

Returns:



1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 1093

def activities(options = {})
  batches = Enumerator.new do |y|
    options = options.merge(auto_scaling_group_name: @name)
    resp = @client.describe_scaling_activities(options)
    resp.each_page do |page|
      batch = []
      page.data.activities.each do |a|
        batch << Activity.new(
          id: a.activity_id,
          data: a,
          client: @client
        )
      end
      y.yield(batch)
    end
  end
  Activity::Collection.new(batches)
end

#attach_instances(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


auto_scaling_group.attach_instances({
  instance_ids: ["XmlStringMaxLen19"],
})

Parameters:

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

    ({})

Options Hash (options):

  • :instance_ids (Array<String>)

    The IDs of the instances. You can specify up to 20 instances.

Returns:

  • (EmptyStructure)


397
398
399
400
401
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 397

def attach_instances(options = {})
  options = options.merge(auto_scaling_group_name: @name)
  resp = @client.attach_instances(options)
  resp.data
end

#auto_scaling_group_arnString

The Amazon Resource Name (ARN) of the Auto Scaling group.

Returns:

  • (String)


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

def auto_scaling_group_arn
  data[:auto_scaling_group_arn]
end

#availability_zonesArray<String>

One or more Availability Zones for the group.

Returns:

  • (Array<String>)


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

def availability_zones
  data[:availability_zones]
end

#clientClient

Returns:



192
193
194
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 192

def client
  @client
end

#created_timeTime

The date and time the group was created.

Returns:

  • (Time)


124
125
126
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 124

def created_time
  data[:created_time]
end

#dataTypes::AutoScalingGroup



212
213
214
215
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 212

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.



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

def data_loaded?
  !!@data
end

#default_cooldownInteger

The duration of the default cooldown period, in seconds.

Returns:

  • (Integer)


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

def default_cooldown
  data[:default_cooldown]
end

#delete(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


auto_scaling_group.delete({
  force_delete: false,
})

Parameters:

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

    ({})

Options Hash (options):

  • :force_delete (Boolean)

    Specifies that the group is to be deleted along with all instances associated with the group, without waiting for all instances to be terminated. This parameter also deletes any lifecycle actions associated with the group.

Returns:

  • (EmptyStructure)


415
416
417
418
419
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 415

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

#desired_capacityInteger

The desired size of the group.

Returns:

  • (Integer)


76
77
78
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 76

def desired_capacity
  data[:desired_capacity]
end

#detach_instances(options = {}) ⇒ Activity::Collection

Examples:

Request syntax with placeholder values


activity = auto_scaling_group.detach_instances({
  instance_ids: ["XmlStringMaxLen19"],
  should_decrement_desired_capacity: false, # required
})

Parameters:

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

    ({})

Options Hash (options):

  • :instance_ids (Array<String>)

    The IDs of the instances. You can specify up to 20 instances.

  • :should_decrement_desired_capacity (required, Boolean)

    Indicates whether the Auto Scaling group decrements the desired capacity value by the number of instances detached.

Returns:



434
435
436
437
438
439
440
441
442
443
444
445
446
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 434

def detach_instances(options = {})
  batch = []
  options = options.merge(auto_scaling_group_name: @name)
  resp = @client.detach_instances(options)
  resp.data.activities.each do |a|
    batch << Activity.new(
      id: a.activity_id,
      data: a,
      client: @client
    )
  end
  Activity::Collection.new([batch], size: batch.size)
end

#disable_metrics_collection(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


auto_scaling_group.disable_metrics_collection({
  metrics: ["XmlStringMaxLen255"],
})

Parameters:

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

    ({})

Options Hash (options):

  • :metrics (Array<String>)

    Specifies one or more of the following metrics:

    • GroupMinSize

    • GroupMaxSize

    • GroupDesiredCapacity

    • GroupInServiceInstances

    • GroupPendingInstances

    • GroupStandbyInstances

    • GroupTerminatingInstances

    • GroupTotalInstances

    • GroupInServiceCapacity

    • GroupPendingCapacity

    • GroupStandbyCapacity

    • GroupTerminatingCapacity

    • GroupTotalCapacity

    If you omit this parameter, all metrics are disabled.

Returns:

  • (EmptyStructure)


485
486
487
488
489
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 485

def disable_metrics_collection(options = {})
  options = options.merge(auto_scaling_group_name: @name)
  resp = @client.disable_metrics_collection(options)
  resp.data
end

#enable_metrics_collection(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


auto_scaling_group.enable_metrics_collection({
  metrics: ["XmlStringMaxLen255"],
  granularity: "XmlStringMaxLen255", # required
})

Parameters:

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

    ({})

Options Hash (options):

  • :metrics (Array<String>)

    Specifies which group-level metrics to start collecting. You can specify one or more of the following metrics:

    • GroupMinSize

    • GroupMaxSize

    • GroupDesiredCapacity

    • GroupInServiceInstances

    • GroupPendingInstances

    • GroupStandbyInstances

    • GroupTerminatingInstances

    • GroupTotalInstances

    The instance weighting feature supports the following additional metrics:

    • GroupInServiceCapacity

    • GroupPendingCapacity

    • GroupStandbyCapacity

    • GroupTerminatingCapacity

    • GroupTotalCapacity

    If you omit this parameter, all metrics are enabled.

  • :granularity (required, String)

    The granularity to associate with the metrics to collect. The only valid value is 1Minute.

Returns:

  • (EmptyStructure)


536
537
538
539
540
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 536

def enable_metrics_collection(options = {})
  options = options.merge(auto_scaling_group_name: @name)
  resp = @client.enable_metrics_collection(options)
  resp.data
end

#enabled_metricsArray<Types::EnabledMetric>

The metrics enabled for the group.

Returns:



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

def enabled_metrics
  data[:enabled_metrics]
end

#exists?(options = {}) ⇒ Boolean

Returns true if the AutoScalingGroup exists.

Parameters:

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

    ({})

Returns:

  • (Boolean)

    Returns true if the AutoScalingGroup exists.



227
228
229
230
231
232
233
234
235
236
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 227

def exists?(options = {})
  begin
    wait_until_exists(options.merge(max_attempts: 1))
    true
  rescue Aws::Waiters::Errors::UnexpectedError => e
    raise e.error
  rescue Aws::Waiters::Errors::WaiterFailed
    false
  end
end

#health_check_grace_periodInteger

The amount of time, in seconds, that Amazon EC2 Auto Scaling waits before checking the health status of an EC2 instance that has come into service.

Returns:

  • (Integer)


118
119
120
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 118

def health_check_grace_period
  data[:health_check_grace_period]
end

#health_check_typeString

The service to use for the health checks. The valid values are EC2 and ELB. If you configure an Auto Scaling group to use ELB health checks, it considers the instance unhealthy if it fails either the EC2 status checks or the load balancer health checks.

Returns:

  • (String)


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

def health_check_type
  data[:health_check_type]
end

#instancesInstance::Collection



1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 1113

def instances
  batch = []
  data[:instances].each do |d|
    batch << Instance.new(
      group_name: @name,
      id: d[:instance_id],
      data: d,
      client: @client
    )
  end
  Instance::Collection.new([batch], size: batch.size)
end

#launch_configurationLaunchConfiguration?

Returns:



1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 1127

def launch_configuration
  if data[:launch_configuration_name]
    LaunchConfiguration.new(
      name: data[:launch_configuration_name],
      client: @client
    )
  else
    nil
  end
end

#launch_configuration_nameString

The name of the associated launch configuration.

Returns:

  • (String)


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

def launch_configuration_name
  data[:launch_configuration_name]
end

#launch_templateTypes::LaunchTemplateSpecification

The launch template for the group.



52
53
54
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 52

def launch_template
  data[:launch_template]
end

#lifecycle_hook(name) ⇒ LifecycleHook

Parameters:

  • name (String)

Returns:



1140
1141
1142
1143
1144
1145
1146
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 1140

def lifecycle_hook(name)
  LifecycleHook.new(
    group_name: @name,
    name: name,
    client: @client
  )
end

#lifecycle_hooks(options = {}) ⇒ LifecycleHook::Collection

Examples:

Request syntax with placeholder values


lifecycle_hooks = auto_scaling_group.lifecycle_hooks({
  lifecycle_hook_names: ["AsciiStringMaxLen255"],
})

Parameters:

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

    ({})

Options Hash (options):

  • :lifecycle_hook_names (Array<String>)

    The names of one or more lifecycle hooks. If you omit this parameter, all lifecycle hooks are described.

Returns:



1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 1158

def lifecycle_hooks(options = {})
  batches = Enumerator.new do |y|
    batch = []
    options = options.merge(auto_scaling_group_name: @name)
    resp = @client.describe_lifecycle_hooks(options)
    resp.data.lifecycle_hooks.each do |l|
      batch << LifecycleHook.new(
        group_name: l.auto_scaling_group_name,
        name: l.lifecycle_hook_name,
        data: l,
        client: @client
      )
    end
    y.yield(batch)
  end
  LifecycleHook::Collection.new(batches)
end

#loadself Also known as: reload

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

auto_scaling_group.reload.data

Returns:

  • (self)


202
203
204
205
206
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 202

def load
  resp = @client.describe_auto_scaling_groups(auto_scaling_group_names: [@name])
  @data = resp.auto_scaling_groups[0]
  self
end

#load_balancer(name) ⇒ LoadBalancer

Parameters:

  • name (String)

Returns:



1178
1179
1180
1181
1182
1183
1184
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 1178

def load_balancer(name)
  LoadBalancer.new(
    group_name: @name,
    name: name,
    client: @client
  )
end

#load_balancer_namesArray<String>

One or more load balancers associated with the group.

Returns:

  • (Array<String>)


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

def load_balancer_names
  data[:load_balancer_names]
end

#load_balancers(options = {}) ⇒ LoadBalancer::Collection

Examples:

Request syntax with placeholder values


load_balancers = auto_scaling_group.load_balancers({
  next_token: "XmlString",
  max_records: 1,
})

Parameters:

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

    ({})

Options Hash (options):

  • :next_token (String)

    The token for the next set of items to return. (You received this token from a previous call.)

  • :max_records (Integer)

    The maximum number of items to return with this call. The default value is 100 and the maximum value is 100.

Returns:



1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 1200

def load_balancers(options = {})
  batches = Enumerator.new do |y|
    batch = []
    options = options.merge(auto_scaling_group_name: @name)
    resp = @client.describe_load_balancers(options)
    resp.data.load_balancers.each do |l|
      batch << LoadBalancer.new(
        group_name: @name,
        name: l.load_balancer_name,
        data: l,
        client: @client
      )
    end
    y.yield(batch)
  end
  LoadBalancer::Collection.new(batches)
end

#max_instance_lifetimeInteger

The maximum amount of time, in seconds, that an instance can be in service.

Valid Range: Minimum value of 0.

Returns:

  • (Integer)


185
186
187
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 185

def max_instance_lifetime
  data[:max_instance_lifetime]
end

#max_sizeInteger

The maximum size of the group.

Returns:

  • (Integer)


70
71
72
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 70

def max_size
  data[:max_size]
end

#min_sizeInteger

The minimum size of the group.

Returns:

  • (Integer)


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

def min_size
  data[:min_size]
end

#mixed_instances_policyTypes::MixedInstancesPolicy

The mixed instances policy for the group.



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

def mixed_instances_policy
  data[:mixed_instances_policy]
end

#nameString Also known as: auto_scaling_group_name

Returns:

  • (String)


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

def name
  @name
end

#new_instances_protected_from_scale_inBoolean

Indicates whether newly launched instances are protected from termination by Amazon EC2 Auto Scaling when scaling in.

Returns:

  • (Boolean)


169
170
171
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 169

def new_instances_protected_from_scale_in
  data[:new_instances_protected_from_scale_in]
end

#notification_configurations(options = {}) ⇒ NotificationConfiguration::Collection

Examples:

Request syntax with placeholder values


auto_scaling_group.notification_configurations()

Parameters:

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

    ({})

Returns:



1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 1223

def notification_configurations(options = {})
  batches = Enumerator.new do |y|
    options = Aws::Util.deep_merge(options, auto_scaling_group_names: [@name])
    resp = @client.describe_notification_configurations(options)
    resp.each_page do |page|
      batch = []
      page.data.notification_configurations.each do |n|
        batch << NotificationConfiguration.new(
          group_name: n.auto_scaling_group_name,
          type: n.notification_type,
          topic_arn: n.topic_arn,
          data: n,
          client: @client
        )
      end
      y.yield(batch)
    end
  end
  NotificationConfiguration::Collection.new(batches)
end

#placement_groupString

The name of the placement group into which to launch your instances, if any.

Returns:

  • (String)


137
138
139
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 137

def placement_group
  data[:placement_group]
end

#policies(options = {}) ⇒ ScalingPolicy::Collection

Examples:

Request syntax with placeholder values


policies = auto_scaling_group.policies({
  policy_names: ["ResourceName"],
  policy_types: ["XmlStringMaxLen64"],
})

Parameters:

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

    ({})

Options Hash (options):

  • :policy_names (Array<String>)

    The names of one or more policies. If you omit this parameter, all policies are described. If a group name is provided, the results are limited to that group. This list is limited to 50 items. If you specify an unknown policy name, it is ignored with no error.

  • :policy_types (Array<String>)

    One or more policy types. The valid values are SimpleScaling, StepScaling, and TargetTrackingScaling.

Returns:



1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 1260

def policies(options = {})
  batches = Enumerator.new do |y|
    options = options.merge(auto_scaling_group_name: @name)
    resp = @client.describe_policies(options)
    resp.each_page do |page|
      batch = []
      page.data.scaling_policies.each do |s|
        batch << ScalingPolicy.new(
          name: s.policy_name,
          data: s,
          client: @client
        )
      end
      y.yield(batch)
    end
  end
  ScalingPolicy::Collection.new(batches)
end

#put_scaling_policy(options = {}) ⇒ ScalingPolicy

Examples:

Request syntax with placeholder values


scalingpolicy = auto_scaling_group.put_scaling_policy({
  policy_name: "XmlStringMaxLen255", # required
  policy_type: "XmlStringMaxLen64",
  adjustment_type: "XmlStringMaxLen255",
  min_adjustment_step: 1,
  min_adjustment_magnitude: 1,
  scaling_adjustment: 1,
  cooldown: 1,
  metric_aggregation_type: "XmlStringMaxLen32",
  step_adjustments: [
    {
      metric_interval_lower_bound: 1.0,
      metric_interval_upper_bound: 1.0,
      scaling_adjustment: 1, # required
    },
  ],
  estimated_instance_warmup: 1,
  target_tracking_configuration: {
    predefined_metric_specification: {
      predefined_metric_type: "ASGAverageCPUUtilization", # required, accepts ASGAverageCPUUtilization, ASGAverageNetworkIn, ASGAverageNetworkOut, ALBRequestCountPerTarget
      resource_label: "XmlStringMaxLen1023",
    },
    customized_metric_specification: {
      metric_name: "MetricName", # required
      namespace: "MetricNamespace", # required
      dimensions: [
        {
          name: "MetricDimensionName", # required
          value: "MetricDimensionValue", # required
        },
      ],
      statistic: "Average", # required, accepts Average, Minimum, Maximum, SampleCount, Sum
      unit: "MetricUnit",
    },
    target_value: 1.0, # required
    disable_scale_in: false,
  },
  enabled: false,
})

Parameters:

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

    ({})

Options Hash (options):

  • :policy_name (required, String)

    The name of the policy.

  • :policy_type (String)

    One of the following policy types:

    • TargetTrackingScaling

    • StepScaling

    • SimpleScaling (default)

  • :adjustment_type (String)

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

    Required if the policy type is StepScaling or SimpleScaling. For more information, see Scaling Adjustment Types in the Amazon EC2 Auto Scaling User Guide.

  • :min_adjustment_step (Integer)

    Available for backward compatibility. Use MinAdjustmentMagnitude instead.

  • :min_adjustment_magnitude (Integer)

    The minimum value to scale by when the adjustment type is PercentChangeInCapacity. For example, suppose that you create a step scaling policy to scale out an Auto Scaling group by 25 percent and you specify a MinAdjustmentMagnitude of 2. If the group has 4 instances and the scaling policy is performed, 25 percent of 4 is 1. However, because you specified a MinAdjustmentMagnitude of 2, Amazon EC2 Auto Scaling scales out the group by 2 instances.

    Valid only if the policy type is StepScaling or SimpleScaling. For more information, see Scaling Adjustment Types in the Amazon EC2 Auto Scaling User Guide.

    Some Auto Scaling groups use instance weights. In this case, set the MinAdjustmentMagnitude to a value that is at least as large as your largest instance weight.

  • :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. For exact capacity, you must specify a positive value.

    Required if the policy type is SimpleScaling. (Not used with any other policy type.)

  • :cooldown (Integer)

    The duration of the policy's cooldown period, in seconds. When a cooldown period is specified here, it overrides the default cooldown period defined for the Auto Scaling group.

    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.

  • :metric_aggregation_type (String)

    The aggregation type for the CloudWatch metrics. The valid values are Minimum, Maximum, and Average. If the aggregation type is null, the value is treated as Average.

    Valid only if the policy type is StepScaling.

  • :step_adjustments (Array<Types::StepAdjustment>)

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

    Required if the policy type is StepScaling. (Not used with any other policy type.)

  • :estimated_instance_warmup (Integer)

    The estimated time, in seconds, until a newly launched instance can contribute to the CloudWatch metrics. If not provided, the default is to use the value from the default cooldown period for the Auto Scaling group.

    Valid only if the policy type is TargetTrackingScaling or StepScaling.

  • :target_tracking_configuration (Types::TargetTrackingConfiguration)

    A target tracking scaling policy. Includes support for predefined or customized metrics.

    The following predefined metrics are available:

    • ASGAverageCPUUtilization

    • ASGAverageNetworkIn

    • ASGAverageNetworkOut

    • ALBRequestCountPerTarget

    If you specify ALBRequestCountPerTarget for the metric, you must specify the ResourceLabel parameter with the PredefinedMetricSpecification.

    For more information, see TargetTrackingConfiguration in the Amazon EC2 Auto Scaling API Reference.

    Required if the policy type is TargetTrackingScaling.

  • :enabled (Boolean)

    Indicates whether the scaling policy is enabled or disabled. The default is enabled. For more information, see Disabling a Scaling Policy for an Auto Scaling Group in the Amazon EC2 Auto Scaling User Guide.

Returns:



707
708
709
710
711
712
713
714
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 707

def put_scaling_policy(options = {})
  options = options.merge(auto_scaling_group_name: @name)
  @client.put_scaling_policy(options)
  ScalingPolicy.new(
    name: options[:policy_name],
    client: @client
  )
end

#put_scheduled_update_group_action(options = {}) ⇒ ScheduledAction

Examples:

Request syntax with placeholder values


scheduledaction = auto_scaling_group.put_scheduled_update_group_action({
  scheduled_action_name: "XmlStringMaxLen255", # required
  time: Time.now,
  start_time: Time.now,
  end_time: Time.now,
  recurrence: "XmlStringMaxLen255",
  min_size: 1,
  max_size: 1,
  desired_capacity: 1,
})

Parameters:

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

    ({})

Options Hash (options):

  • :scheduled_action_name (required, String)

    The name of this scaling action.

  • :time (Time, DateTime, Date, Integer, String)

    This parameter is no longer used.

  • :start_time (Time, DateTime, Date, Integer, String)

    The date and time for this action to start, in YYYY-MM-DDThh:mm:ssZ format in UTC/GMT only and in quotes (for example, "2019-06-01T00:00:00Z").

    If you specify Recurrence and StartTime, Amazon EC2 Auto Scaling performs the action at this time, and then performs the action based on the specified recurrence.

    If you try to schedule your action in the past, Amazon EC2 Auto Scaling returns an error message.

  • :end_time (Time, DateTime, Date, Integer, String)

    The date and time for the recurring schedule to end. Amazon EC2 Auto Scaling does not perform the action after this time.

  • :recurrence (String)

    The recurring schedule for this action, in Unix cron syntax format. This format consists of five fields separated by white spaces: [Minute] [Hour] [Day_of_Month] [Month_of_Year] [Day_of_Week]. The value must be in quotes (for example, "30 0 1 1,6,12 *"). For more information about this format, see Crontab.

    When StartTime and EndTime are specified with Recurrence, they form the boundaries of when the recurring action starts and stops.

  • :min_size (Integer)

    The minimum size of the Auto Scaling group.

  • :max_size (Integer)

    The maximum size of the Auto Scaling group.

  • :desired_capacity (Integer)

    The desired capacity is the initial capacity of the Auto Scaling group after the scheduled action runs and the capacity it attempts to maintain. It can scale beyond this capacity if you add more scaling conditions.

Returns:



770
771
772
773
774
775
776
777
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 770

def put_scheduled_update_group_action(options = {})
  options = options.merge(auto_scaling_group_name: @name)
  @client.put_scheduled_update_group_action(options)
  ScheduledAction.new(
    name: options[:scheduled_action_name],
    client: @client
  )
end

#resume_processes(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


auto_scaling_group.resume_processes({
  scaling_processes: ["XmlStringMaxLen255"],
})

Parameters:

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

    ({})

Options Hash (options):

  • :scaling_processes (Array<String>)

    One or more of the following processes:

    • Launch

    • Terminate

    • AddToLoadBalancer

    • AlarmNotification

    • AZRebalance

    • HealthCheck

    • InstanceRefresh

    • ReplaceUnhealthy

    • ScheduledActions

    If you omit this parameter, all processes are specified.

Returns:

  • (EmptyStructure)


808
809
810
811
812
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 808

def resume_processes(options = {})
  options = options.merge(auto_scaling_group_name: @name)
  resp = @client.resume_processes(options)
  resp.data
end

#scheduled_actions(options = {}) ⇒ ScheduledAction::Collection

Examples:

Request syntax with placeholder values


scheduled_actions = auto_scaling_group.scheduled_actions({
  scheduled_action_names: ["ResourceName"],
  start_time: Time.now,
  end_time: Time.now,
})

Parameters:

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

    ({})

Options Hash (options):

  • :scheduled_action_names (Array<String>)

    The names of one or more scheduled actions. You can specify up to 50 actions. If you omit this parameter, all scheduled actions are described. If you specify an unknown scheduled action, it is ignored with no error.

  • :start_time (Time, DateTime, Date, Integer, String)

    The earliest scheduled start time to return. If scheduled action names are provided, this parameter is ignored.

  • :end_time (Time, DateTime, Date, Integer, String)

    The latest scheduled start time to return. If scheduled action names are provided, this parameter is ignored.

Returns:



1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 1299

def scheduled_actions(options = {})
  batches = Enumerator.new do |y|
    options = options.merge(auto_scaling_group_name: @name)
    resp = @client.describe_scheduled_actions(options)
    resp.each_page do |page|
      batch = []
      page.data.scheduled_update_group_actions.each do |s|
        batch << ScheduledAction.new(
          name: s.scheduled_action_name,
          data: s,
          client: @client
        )
      end
      y.yield(batch)
    end
  end
  ScheduledAction::Collection.new(batches)
end

#service_linked_role_arnString

The Amazon Resource Name (ARN) of the service-linked role that the Auto Scaling group uses to call other AWS services on your behalf.

Returns:

  • (String)


176
177
178
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 176

def service_linked_role_arn
  data[:service_linked_role_arn]
end

#set_desired_capacity(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


auto_scaling_group.set_desired_capacity({
  desired_capacity: 1, # required
  honor_cooldown: false,
})

Parameters:

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

    ({})

Options Hash (options):

  • :desired_capacity (required, Integer)

    The desired capacity is the initial capacity of the Auto Scaling group after this operation completes and the capacity it attempts to maintain.

  • :honor_cooldown (Boolean)

    Indicates whether Amazon EC2 Auto Scaling waits for the cooldown period to complete before initiating a scaling activity to set your Auto Scaling group to its new capacity. By default, Amazon EC2 Auto Scaling does not honor the cooldown period during manual scaling activities.

Returns:

  • (EmptyStructure)


832
833
834
835
836
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 832

def set_desired_capacity(options = {})
  options = options.merge(auto_scaling_group_name: @name)
  resp = @client.set_desired_capacity(options)
  resp.data
end

#statusString

The current state of the group when the DeleteAutoScalingGroup operation is in progress.

Returns:

  • (String)


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

def status
  data[:status]
end

#suspend_processes(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


auto_scaling_group.suspend_processes({
  scaling_processes: ["XmlStringMaxLen255"],
})

Parameters:

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

    ({})

Options Hash (options):

  • :scaling_processes (Array<String>)

    One or more of the following processes:

    • Launch

    • Terminate

    • AddToLoadBalancer

    • AlarmNotification

    • AZRebalance

    • HealthCheck

    • InstanceRefresh

    • ReplaceUnhealthy

    • ScheduledActions

    If you omit this parameter, all processes are specified.

Returns:

  • (EmptyStructure)


867
868
869
870
871
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 867

def suspend_processes(options = {})
  options = options.merge(auto_scaling_group_name: @name)
  resp = @client.suspend_processes(options)
  resp.data
end

#suspended_processesArray<Types::SuspendedProcess>

The suspended processes associated with the group.

Returns:



130
131
132
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 130

def suspended_processes
  data[:suspended_processes]
end

#tag(key) ⇒ Tag

Parameters:

  • key (String)

Returns:



1320
1321
1322
1323
1324
1325
1326
1327
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 1320

def tag(key)
  Tag.new(
    key: key,
    resource_id: @name,
    resource_type: "auto-scaling-group",
    client: @client
  )
end

#tagsTag::Collection

Returns:



1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 1330

def tags
  batch = []
  data[:tags].each do |d|
    batch << Tag.new(
      key: d[:key],
      resource_id: d[:resource_id],
      resource_type: d[:resource_type],
      data: d,
      client: @client
    )
  end
  Tag::Collection.new([batch], size: batch.size)
end

#target_group_arnsArray<String>

The Amazon Resource Names (ARN) of the target groups for your load balancer.

Returns:

  • (Array<String>)


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

def target_group_arns
  data[:target_group_arns]
end

#termination_policiesArray<String>

The termination policies for the group.

Returns:

  • (Array<String>)


162
163
164
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 162

def termination_policies
  data[:termination_policies]
end

#update(options = {}) ⇒ AutoScalingGroup

Examples:

Request syntax with placeholder values


autoscalinggroup = auto_scaling_group.update({
  launch_configuration_name: "ResourceName",
  launch_template: {
    launch_template_id: "XmlStringMaxLen255",
    launch_template_name: "LaunchTemplateName",
    version: "XmlStringMaxLen255",
  },
  mixed_instances_policy: {
    launch_template: {
      launch_template_specification: {
        launch_template_id: "XmlStringMaxLen255",
        launch_template_name: "LaunchTemplateName",
        version: "XmlStringMaxLen255",
      },
      overrides: [
        {
          instance_type: "XmlStringMaxLen255",
          weighted_capacity: "XmlStringMaxLen32",
        },
      ],
    },
    instances_distribution: {
      on_demand_allocation_strategy: "XmlString",
      on_demand_base_capacity: 1,
      on_demand_percentage_above_base_capacity: 1,
      spot_allocation_strategy: "XmlString",
      spot_instance_pools: 1,
      spot_max_price: "MixedInstanceSpotPrice",
    },
  },
  min_size: 1,
  max_size: 1,
  desired_capacity: 1,
  default_cooldown: 1,
  availability_zones: ["XmlStringMaxLen255"],
  health_check_type: "XmlStringMaxLen32",
  health_check_grace_period: 1,
  placement_group: "XmlStringMaxLen255",
  vpc_zone_identifier: "XmlStringMaxLen2047",
  termination_policies: ["XmlStringMaxLen1600"],
  new_instances_protected_from_scale_in: false,
  service_linked_role_arn: "ResourceName",
  max_instance_lifetime: 1,
})

Parameters:

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

    ({})

Options Hash (options):

  • :launch_configuration_name (String)

    The name of the launch configuration. If you specify LaunchConfigurationName in your update request, you can't specify LaunchTemplate or MixedInstancesPolicy.

  • :launch_template (Types::LaunchTemplateSpecification)

    The launch template and version to use to specify the updates. If you specify LaunchTemplate in your update request, you can't specify LaunchConfigurationName or MixedInstancesPolicy.

    For more information, see LaunchTemplateSpecification in the Amazon EC2 Auto Scaling API Reference.

  • :mixed_instances_policy (Types::MixedInstancesPolicy)

    An embedded object that specifies a mixed instances policy.

    In your call to UpdateAutoScalingGroup, you can make changes to the policy that is specified. All optional parameters are left unchanged if not specified.

    For more information, see MixedInstancesPolicy in the Amazon EC2 Auto Scaling API Reference and Auto Scaling Groups with Multiple Instance Types and Purchase Options in the Amazon EC2 Auto Scaling User Guide.

  • :min_size (Integer)

    The minimum size of the Auto Scaling group.

  • :max_size (Integer)

    The maximum size of the Auto Scaling group.

    With a mixed instances policy that uses instance weighting, Amazon EC2 Auto Scaling may need to go above MaxSize to meet your capacity requirements. In this event, Amazon EC2 Auto Scaling will never go above MaxSize by more than your maximum instance weight (weights that define how many capacity units each instance contributes to the capacity of the group).

  • :desired_capacity (Integer)

    The desired capacity is the initial capacity of the Auto Scaling group after this operation completes and the capacity it attempts to maintain.

    This number must be greater than or equal to the minimum size of the group and less than or equal to the maximum size of the group.

  • :default_cooldown (Integer)

    The amount of time, in seconds, after a scaling activity completes before another scaling activity can start. The default value is 300.

    This setting applies when using simple scaling policies, but not when using other scaling policies or scheduled scaling. For more information, see Scaling Cooldowns for Amazon EC2 Auto Scaling in the Amazon EC2 Auto Scaling User Guide.

  • :availability_zones (Array<String>)

    One or more Availability Zones for the group.

  • :health_check_type (String)

    The service to use for the health checks. The valid values are EC2 and ELB. If you configure an Auto Scaling group to use ELB health checks, it considers the instance unhealthy if it fails either the EC2 status checks or the load balancer health checks.

  • :health_check_grace_period (Integer)

    The amount of time, in seconds, that Amazon EC2 Auto Scaling waits before checking the health status of an EC2 instance that has come into service. The default value is 0.

    For more information, see Health Check Grace Period in the Amazon EC2 Auto Scaling User Guide.

    Required if you are adding an ELB health check.

  • :placement_group (String)

    The name of the placement group into which to launch your instances, if any. A placement group is a logical grouping of instances within a single Availability Zone. You cannot specify multiple Availability Zones and a placement group. For more information, see Placement Groups in the Amazon EC2 User Guide for Linux Instances.

  • :vpc_zone_identifier (String)

    A comma-separated list of subnet IDs for virtual private cloud (VPC).

    If you specify VPCZoneIdentifier with AvailabilityZones, the subnets that you specify for this parameter must reside in those Availability Zones.

  • :termination_policies (Array<String>)

    A standalone termination policy or a list of termination policies used to select the instance to terminate. The policies are executed in the order that they are listed.

    For more information, see Controlling Which Instances Auto Scaling Terminates During Scale In in the Amazon EC2 Auto Scaling User Guide.

  • :new_instances_protected_from_scale_in (Boolean)

    Indicates whether newly launched instances are protected from termination by Amazon EC2 Auto Scaling when scaling in.

    For more information about preventing instances from terminating on scale in, see Instance Protection in the Amazon EC2 Auto Scaling User Guide.

  • :service_linked_role_arn (String)

    The Amazon Resource Name (ARN) of the service-linked role that the Auto Scaling group uses to call other AWS services on your behalf. For more information, see Service-Linked Roles in the Amazon EC2 Auto Scaling User Guide.

  • :max_instance_lifetime (Integer)

    The maximum amount of time, in seconds, that an instance can be in service. The default is null.

    This parameter is optional, but if you specify a value for it, you must specify a value of at least 604,800 seconds (7 days). To clear a previously set value, specify a new value of 0.

    For more information, see Replacing Auto Scaling Instances Based on Maximum Instance Lifetime in the Amazon EC2 Auto Scaling User Guide.

    Valid Range: Minimum value of 0.

Returns:



1069
1070
1071
1072
1073
1074
1075
1076
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 1069

def update(options = {})
  options = options.merge(auto_scaling_group_name: @name)
  @client.update_auto_scaling_group(options)
  AutoScalingGroup.new(
    name: options[:auto_scaling_group_name],
    client: @client
  )
end

#vpc_zone_identifierString

One or more subnet IDs, if applicable, separated by commas.

Returns:

  • (String)


143
144
145
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 143

def vpc_zone_identifier
  data[:vpc_zone_identifier]
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



369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 369

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

#wait_until_exists(options = {}, &block) ⇒ AutoScalingGroup

Parameters:

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

    ({})

Options Hash (options):

  • :max_attempts (Integer) — default: 10
  • :delay (Float) — default: 5
  • :before_attempt (Proc)
  • :before_wait (Proc)

Returns:



244
245
246
247
248
249
250
251
252
253
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 244

def wait_until_exists(options = {}, &block)
  options, params = separate_params_and_options(options)
  waiter = Waiters::GroupExists.new(options)
  yield_waiter_and_warn(waiter, &block) if block_given?
  waiter.wait(params.merge(auto_scaling_group_names: [@name]))
  AutoScalingGroup.new({
    name: @name,
    client: @client
  })
end

#wait_until_in_service(options = {}, &block) ⇒ AutoScalingGroup

Parameters:

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

    ({})

Options Hash (options):

  • :max_attempts (Integer) — default: 40
  • :delay (Float) — default: 15
  • :before_attempt (Proc)
  • :before_wait (Proc)

Returns:



261
262
263
264
265
266
267
268
269
270
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 261

def wait_until_in_service(options = {}, &block)
  options, params = separate_params_and_options(options)
  waiter = Waiters::GroupInService.new(options)
  yield_waiter_and_warn(waiter, &block) if block_given?
  waiter.wait(params.merge(auto_scaling_group_names: [@name]))
  AutoScalingGroup.new({
    name: @name,
    client: @client
  })
end

#wait_until_not_exists(options = {}, &block) ⇒ AutoScalingGroup

Parameters:

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

    ({})

Options Hash (options):

  • :max_attempts (Integer) — default: 40
  • :delay (Float) — default: 15
  • :before_attempt (Proc)
  • :before_wait (Proc)

Returns:



278
279
280
281
282
283
284
285
286
287
# File 'gems/aws-sdk-autoscaling/lib/aws-sdk-autoscaling/auto_scaling_group.rb', line 278

def wait_until_not_exists(options = {}, &block)
  options, params = separate_params_and_options(options)
  waiter = Waiters::GroupNotExists.new(options)
  yield_waiter_and_warn(waiter, &block) if block_given?
  waiter.wait(params.merge(auto_scaling_group_names: [@name]))
  AutoScalingGroup.new({
    name: @name,
    client: @client
  })
end