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

Class: AWS::AutoScaling::Group

Inherits:
Core::Resource
  • Object
show all
Defined in:
lib/aws/auto_scaling/group.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Group



51
52
53
54
# File 'lib/aws/auto_scaling/group.rb', line 51

def initialize name, options = {}
  @name = name
  super
end

Instance Attribute Details

#availability_zone_namesArray<String> (readonly)

Returns the current value of availability_zone_names

Returns:

  • (Array<String>)

    the current value of availability_zone_names



47
48
49
# File 'lib/aws/auto_scaling/group.rb', line 47

def availability_zone_names
  @availability_zone_names
end

#created_timeTime (readonly)

Returns the current value of created_time

Returns:

  • (Time)

    the current value of created_time



47
48
49
# File 'lib/aws/auto_scaling/group.rb', line 47

def created_time
  @created_time
end

#default_cooldownInteger (readonly)

Returns the current value of default_cooldown

Returns:

  • (Integer)

    the current value of default_cooldown



47
48
49
# File 'lib/aws/auto_scaling/group.rb', line 47

def default_cooldown
  @default_cooldown
end

#desired_capacityInteger (readonly)

Returns the current value of desired_capacity

Returns:

  • (Integer)

    the current value of desired_capacity



47
48
49
# File 'lib/aws/auto_scaling/group.rb', line 47

def desired_capacity
  @desired_capacity
end

#enabled_metricsArray<Hash> (readonly)

Returns a hash of enabled metric names (keys) and granularities (values).

Returns:

  • (Array<Hash>)

    the current value of enabled_metrics



47
48
49
# File 'lib/aws/auto_scaling/group.rb', line 47

def enabled_metrics
  @enabled_metrics
end

#health_check_grace_periodInteger (readonly)

Returns the current value of health_check_grace_period

Returns:

  • (Integer)

    the current value of health_check_grace_period



47
48
49
# File 'lib/aws/auto_scaling/group.rb', line 47

def health_check_grace_period
  @health_check_grace_period
end

#health_check_typeSymbol (readonly)

Returns :ec2 or :vpc.

Returns:

  • (Symbol)

    the current value of health_check_type



47
48
49
# File 'lib/aws/auto_scaling/group.rb', line 47

def health_check_type
  @health_check_type
end

#launch_configuration_nameString (readonly)

Returns the current value of launch_configuration_name

Returns:

  • (String)

    the current value of launch_configuration_name



47
48
49
# File 'lib/aws/auto_scaling/group.rb', line 47

def launch_configuration_name
  @launch_configuration_name
end

#load_balancer_namesArray<String> (readonly)

Returns the current value of load_balancer_names

Returns:

  • (Array<String>)

    the current value of load_balancer_names



47
48
49
# File 'lib/aws/auto_scaling/group.rb', line 47

def load_balancer_names
  @load_balancer_names
end

#max_sizeInteger (readonly)

Returns the current value of max_size

Returns:

  • (Integer)

    the current value of max_size



47
48
49
# File 'lib/aws/auto_scaling/group.rb', line 47

def max_size
  @max_size
end

#min_sizeInteger (readonly)

Returns the current value of min_size

Returns:

  • (Integer)

    the current value of min_size



47
48
49
# File 'lib/aws/auto_scaling/group.rb', line 47

def min_size
  @min_size
end

#nameString (readonly)

Returns:

  • (String)


57
58
59
# File 'lib/aws/auto_scaling/group.rb', line 57

def name
  @name
end

#placement_groupString? (readonly)

Returns the current value of placement_group

Returns:

  • (String, nil)

    the current value of placement_group



47
48
49
# File 'lib/aws/auto_scaling/group.rb', line 47

def placement_group
  @placement_group
end

#suspended_processesHash (readonly)

A hash of suspended process names (keys) and reasons (values).

Returns:

  • (Hash)

    the current value of suspended_processes



47
48
49
# File 'lib/aws/auto_scaling/group.rb', line 47

def suspended_processes
  @suspended_processes
end

Instance Method Details

#activitiesActivityCollection

Returns:



148
149
150
# File 'lib/aws/auto_scaling/group.rb', line 148

def activities
  ActivityCollection.new(:group => self)
end

#auto_scaling_instancesArray<AutoScaling::Instance>

Returns:



153
154
155
156
157
158
159
160
161
162
# File 'lib/aws/auto_scaling/group.rb', line 153

def auto_scaling_instances
  instances.collect do |details|
    Instance.new_from(
      :describe_auto_scaling_groups,
      details,
      details.instance_id,
      :auto_scaling_group_name => name, # not provided by the response
      :config => config)
  end
end

#availability_zonesArray<EC2::AvailabilityZone>

Returns:



189
190
191
192
193
# File 'lib/aws/auto_scaling/group.rb', line 189

def availability_zones
  availability_zone_names.collect do |az_name|
    EC2::AvailabilityZone.new(az_name, :config => config)
  end
end

#delete(options = {}) ⇒ nil

Deletes the Auto Scaling group. If you pass :force as true then all the instances associated with this group will also be terminated.

Parameters:

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

Options Hash (options):

  • :force (Boolean) — default: false

    When true, the Auto Scaling group will be deleted along with all instances associated with the group, without waiting for all instances to be terminated.

Returns:

  • (nil)

See Also:



384
385
386
387
388
389
390
# File 'lib/aws/auto_scaling/group.rb', line 384

def delete options = {}
  client_opts = {}
  client_opts[:force_delete] = options[:force] == true
  client_opts[:auto_scaling_group_name] = name
  client.delete_auto_scaling_group(client_opts)
  nil
end

#delete!nil

Deletes the Auto Scaling group along with all instances associated with the group, without waiting for all instances to be terminated.

Returns:

  • (nil)


396
397
398
399
# File 'lib/aws/auto_scaling/group.rb', line 396

def delete!
  delete(:force => true)
  nil
end

#delete_all_tagsnil

Removes all tags from this Auto Scaling group.

Returns:

  • (nil)


365
366
367
368
# File 'lib/aws/auto_scaling/group.rb', line 365

def delete_all_tags
  delete_tags(self.tags)
  nil
end

#delete_tags(*tags) ⇒ nil

Deletes specific tags from this Auto Scaling group.

group.delete_tags([
  { :key => 'role', :value => 'webserver' },
])

You may also pass Tag objects.

Parameters:

  • tags (Array<Tag,Hash>)

    An array of Tag objects or tag hashes to remove. If you pass hashes they should have the following keys: * :key * :value * :propagate_at_launch

Returns:

  • (nil)


353
354
355
356
357
358
359
360
361
# File 'lib/aws/auto_scaling/group.rb', line 353

def delete_tags *tags
  tags = tags.flatten.collect do |tag|
    tag.to_hash.merge(
      :resource_type => 'auto-scaling-group',
      :resource_id => name)
  end
  client.delete_tags(:tags => tags)
  nil
end

#disable_all_metrics_collectionnil

Disables all metrics collection for the Auto Scaling group.

Returns:

  • (nil)


301
302
303
# File 'lib/aws/auto_scaling/group.rb', line 301

def disable_all_metrics_collection
  disable_metrics_collection
end

#disable_metrics_collection(*metrics) ⇒ nil

Parameters:

  • metrics (Array<String>)

    A list of metrics to collect.

Returns:

  • (nil)


291
292
293
294
295
296
297
# File 'lib/aws/auto_scaling/group.rb', line 291

def disable_metrics_collection *metrics
  client_opts = {}
  client_opts[:auto_scaling_group_name] = name
  client_opts[:metrics] = metrics.flatten
  client.disable_metrics_collection(client_opts)
  nil
end

#ec2_instancesEC2::InstanceCollection

Returns a collection that represents the instances belonging to this Auto Scaling group. You can use this collection to further refine the instances you are interested in:

group.ec2_instances.filter('availability-zone', 'us-west-2a').each do |i|
  puts instance.id
end

Returns:

  • (EC2::InstanceCollection)

    Returns an instance collection (without making a request) that represents the instances belonging to this Auto Scaling group.



176
177
178
179
# File 'lib/aws/auto_scaling/group.rb', line 176

def ec2_instances
  instances = EC2::InstanceCollection.new(:config => config)
  instances.filter('tag:aws:autoscaling:groupName', name)
end

#enable_all_metrics_collectionnil

Enables all metrics collection for the Auto Scaling group.

Returns:

  • (nil)


285
286
287
# File 'lib/aws/auto_scaling/group.rb', line 285

def enable_all_metrics_collection
  enable_metrics_collection
end

#enable_metrics_collection(*metrics) ⇒ nil

Parameters:

  • metrics (Array<String>)

    A list of metrics to collect.

Returns:

  • (nil)


274
275
276
277
278
279
280
281
# File 'lib/aws/auto_scaling/group.rb', line 274

def enable_metrics_collection *metrics
  client_opts = {}
  client_opts[:auto_scaling_group_name] = name
  client_opts[:granularity] = '1Minute'
  client_opts[:metrics] = metrics.flatten
  client.enable_metrics_collection(client_opts)
  nil
end

#exists?Boolean

Returns:

  • (Boolean)


402
403
404
405
406
407
# File 'lib/aws/auto_scaling/group.rb', line 402

def exists?
  client_opts = {}
  client_opts[:auto_scaling_group_names] = [name]
  resp = client.describe_auto_scaling_groups(client_opts)
  !resp.auto_scaling_groups.empty?
end

#launch_configurationLaunchConfiguration

Returns:



143
144
145
# File 'lib/aws/auto_scaling/group.rb', line 143

def launch_configuration
  LaunchConfiguration.new(launch_configuration_name, :config => config)
end

#load_balancersArray, <ELB::LoadBalancer>

Returns:



196
197
198
199
200
# File 'lib/aws/auto_scaling/group.rb', line 196

def load_balancers
  load_balancer_names.collect do |name|
    ELB::LoadBalancer.new(name, :config => config)
  end
end

#notification_configurationsNotificationConfigurationCollection



125
126
127
# File 'lib/aws/auto_scaling/group.rb', line 125

def notification_configurations
  NotificationConfigurationCollection.new(:group => self)
end

#resume_all_processesnil

Resumes all processes for this Auto Scaling group.

Returns:

  • (nil)


268
269
270
# File 'lib/aws/auto_scaling/group.rb', line 268

def resume_all_processes
  resume_processes
end

#resume_processes(*processes) ⇒ nil

Resumes processes for this Auto Scaling group.

# resume two processes by name
auto_scaling_group.suspend_processes 'Launch', 'AZRebalance'

Parameters:

  • processes (Array<String>)

    A list of process to resume.

Returns:

  • (nil)


258
259
260
261
262
263
264
# File 'lib/aws/auto_scaling/group.rb', line 258

def resume_processes *processes
  client_opts = {}
  client_opts[:auto_scaling_group_name] = name
  client_opts[:scaling_processes] = processes.flatten
  client.resume_processes(client_opts)
  nil
end

#scaling_policiesScalingPolicyCollection



120
121
122
# File 'lib/aws/auto_scaling/group.rb', line 120

def scaling_policies
  ScalingPolicyCollection.new(self)
end

#scheduled_actionsScheduledActionCollection



130
131
132
133
# File 'lib/aws/auto_scaling/group.rb', line 130

def scheduled_actions
  actions = ScheduledActionCollection.new(:config => config)
  actions.filter(:group => self)
end

#set_desired_capacity(capacity, options = {}) ⇒ nil

Adjusts the desired size of the Auto Scaling group by initiating scaling activities. When reducing the size of the group, it is not possible to define which Amazon EC2 instances will be terminated. This applies to any Auto Scaling decisions that might result in terminating instances.

Parameters:

  • capacity (Integer)

    The new capacity setting for this Auto Scaling group.

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

Options Hash (options):

  • :honor_cooldown (Boolean) — default: false

Returns:

  • (nil)


217
218
219
220
221
222
223
224
# File 'lib/aws/auto_scaling/group.rb', line 217

def set_desired_capacity capacity, options = {}
  client_opts = {}
  client_opts[:auto_scaling_group_name] = name
  client_opts[:desired_capacity] = capacity
  client_opts[:honor_cooldown] = options[:honor_cooldown] == true
  client.set_desired_capacity(client_opts)
  nil
end

#subnetsArray<EC2::Subnet>

Returns:



182
183
184
185
186
# File 'lib/aws/auto_scaling/group.rb', line 182

def subnets
  vpc_zone_identifier.to_s.split(/,/).collect do |subnet_id|
    EC2::Subnet.new(subnet_id, :config => config)
  end
end

#suspend_all_processesnil

Suspends all processes for this Auto Scaling group.

Returns:

  • (nil)


245
246
247
# File 'lib/aws/auto_scaling/group.rb', line 245

def suspend_all_processes
  suspend_processes
end

#suspend_processes(*processes) ⇒ nil

Suspends processes for this Auto Scaling group.

# suspend two processes by name
auto_scaling_group.suspend_processes 'Launch', 'AZRebalance'

Parameters:

  • processes (Array<String>)

    A list of process to suspend.

Returns:

  • (nil)


235
236
237
238
239
240
241
# File 'lib/aws/auto_scaling/group.rb', line 235

def suspend_processes *processes
  client_opts = {}
  client_opts[:auto_scaling_group_name] = name
  client_opts[:scaling_processes] = processes.flatten
  client.suspend_processes(client_opts)
  nil
end

#tagsTag

Returns:



136
137
138
139
140
# File 'lib/aws/auto_scaling/group.rb', line 136

def tags
  tag_details.collect do |tag|
    Tag.new(tag.to_hash.merge(:config => config))
  end
end

#update(options = {}) ⇒ nil

Update one or more attributes on the Auto Scaling group.

Parameters:

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

Options Hash (options):

  • :min_size (required, Integer)

    The maximum size of the Auto Scaling group.

  • :max_size (required, Integer)

    The minimum size of the Auto Scaling group.

  • :launch_configuration (required, LaunchConfiguration, String)

    The launch configuration to use with the Auto Scaling group. This may be a LaunchConfiguration object or a launch configuration name string.

  • :availability_zones (required, Array<String>)

    A list of Availability Zones for the Auto Scaling group. This can be EC2::AvailabilityZone objects or availability zone names.

  • :default_cooldown (Integer)

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

  • :desired_capacity (Integer)

    The number of Amazon EC2 instances that should be running in the group.

  • :health_check_grace_period (Integer)

    Length of time in seconds after a new Amazon EC2 instance comes into service that Auto Scaling starts checking its health.

  • :health_check_type (Symbol)

    The service you want the health status from, Amazon EC2 or Elastic Load Balancer. Valid values are :ec2 or :elb.

  • :placement_group (String)

    Physical location of your cluster placement group created in Amazon EC2. For more information about cluster placement group, see Using Cluster Instances.

  • :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 they are listed. For more information on creating a termination policy for your Auto Scaling group, go to Instance Termination Policy for Your Auto Scaling Group in the Auto Scaling Developer Guide.

  • :tags (Array<Hash>)

    A list of tags to apply launched instances. Each tag hash may have the following keys:

    • :key - (required,String) The tag name.
    • :value - (String) The optional tag value.
    • :propagate_at_launch - (Boolean) Whether or not to propagate to instances, defaults to true.
  • :subnets (Array<EC2::Subnet>, Array<String>)

    A list of subnet identifiers of Amazon Virtual Private Clouds (Amazon VPCs). Ensure the subnets' Availability Zones match the Availability Zones specified.

Returns:

  • (nil)


313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File 'lib/aws/auto_scaling/group.rb', line 313

def update options = {}

  group_opts = group_options(options)

  # tags must be updated using a separate request from the
  # other attributes, *sigh*
  if tags = group_opts.delete(:tags)
    tags.map(&:to_hash).each do |tag|
      tag[:resource_type] = 'auto-scaling-group'
      tag[:resource_id] = name
    end
    client.create_or_update_tags(:tags => tags)
  end

  unless group_opts.empty?
    client_opts = group_opts.merge(:auto_scaling_group_name => name)
    client.update_auto_scaling_group(client_opts)
  end

  nil

end