Class: AWS::AutoScaling::TagCollection
- Inherits:
-
Object
- Object
- AWS::AutoScaling::TagCollection
- Includes:
- Core::Collection::Limitable
- Defined in:
- lib/aws/auto_scaling/tag_collection.rb
Overview
Provides an interface for enumerating tags defined in Auto Scaling.
auto_scaling = AWS::AutoScaling.new
auto_scaling..each do |tag|
puts "#{tag.key}:#{tag.value}"
end
Filters
You can filter the tags returned using #filter:
# returns tags with the key "role"
auto_scaling.filter(:key, 'role').to_a
# returns tags with the key "role" and value "webserver"
auto_scaling.filter(:key, 'role').filter(:value, 'webserver')to_a
# returns tags with the Auto Scaling group name "group1"
auto_scaling.filter(:auto_scaling_group, 'group1').to_a
# returns all tags that propagate at launch
auto_scaling.filter(:propagate_at_launch, true).to_a
Creating Tags
You can create Auto Scaling tags when you:
-
[create]GroupCollection#create an Auto Scaling group
-
[update]Group#update an Auto Scaling group
Both of these methods accept a :tags
option.
tags = [
{ :key => 'auto-scaling-instance' }, # tag name only
{ :key => 'role', :value => 'webserver' }, # tag name and value
]
# creating a group with tags
group = auto_scaling.groups.create('group-name', :tags => tags, ...)
# updating a group's tags
group.update(:tags => tags)
Instance Method Summary collapse
-
#filter(name, *values) ⇒ TagCollection
Filters the tags by the given filter name and value(s).
Methods included from Core::Collection::Limitable
Methods included from Core::Collection
#each, #each_batch, #enum, #first, #in_groups_of, #page
Instance Method Details
#filter(name, *values) ⇒ TagCollection
Filters the tags by the given filter name and value(s).
# return tags with the key "role" and the value "webserver"
auto_scaling..filter(:key, 'role').filer(:value, 'webserver')
86 87 88 89 90 91 |
# File 'lib/aws/auto_scaling/tag_collection.rb', line 86 def filter name, *values name = name.to_s.gsub(/_/, '-') values = values.flatten.map(&:to_s) filter = { :name => name, :values => values } TagCollection.new(:filters => @filters + [filter], :config => config) end |