Class: AWS::AutoScaling::NotificationConfigurationCollection

Inherits:
Object
  • Object
show all
Includes:
Core::Collection::WithLimitAndNextToken
Defined in:
lib/aws/auto_scaling/notification_configuration_collection.rb

Overview

Allows you to enumerate and create notification configurations.#

Enumerating Notification Configurations

You can enumerated ALL configurations from the AWS::AutoScaling class.

auto_scaling = AWS::AutoScaling.new
auto_scaling.notification_configurations.each do |config|
  # ...
end

You can also limit them to a single Auto Scaling group:

group = auto_scaling.groups['group-name']
group.notification_configurations.each do |config|
  # ...
end

Creating Notification Configurations

You can create a notification configuration like so:

auto_scaling.notification_configurations.create(
  :group => 'auto-scaling-group-name',
  :topic => 'sns-topic-arn')

Just like with enumeration, you can create them from the Auto Scaling group:

group.notification_configurations.create(:topic => 'sns-topic-arn')

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Core::Collection

#each_batch, #enum, #first, #in_groups_of, #page

Instance Attribute Details

#groupGroup? (readonly) Also known as: auto_scaling_group

Returns If this collection was initialized with an Auto Scaling group, then that group is returned, nil otherwise.

Returns:

  • (Group, nil)

    If this collection was initialized with an Auto Scaling group, then that group is returned, nil otherwise.



64
65
66
# File 'lib/aws/auto_scaling/notification_configuration_collection.rb', line 64

def group
  @group
end

Instance Method Details

#create(options = {}) ⇒ NotificationConfiguration Also known as: put

Creates a new notification configuration. To create a notification configuration you need an SNS::Topic and an Auto Scaling Group.

auto_scaling.notification_configurations.create(
  :group => 'auto-scaling-group-name', 
  :topic => 'sns-topic-arn')

You can also create notification configurations from an Auto Scaling group and omit the :group option.

auto_scaling_group.notification_configurations.create(
  :topic => 'sns-topic-arn')

You may also pass a list of notification types to publish to the topic. If you omit this option, then all notification types will be configured.

# publish only these two specific notification types
auto_scaling_group.notification_configurations.create(
  :topic => 'sns-topic-arn',
  :types => [
    'autoscaling:EC2_INSTANCE_LAUNCH',
    'autoscaling:EC2_INSTANCE_TERMINATE',
  ]
)

Parameters:

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

Options Hash (options):

  • :topic (required, SNS::Topic, String)

    An SNS::Topic object or a topic arn string. Notifications will be published to this topic.

  • :group (Group, String)

    An Auto Scaling Group object or the name of an Auto Scaling group. This is required if you this collection is not scoped by a Group.

  • :types (Array<String>)

    A list of notification types that should publish messages to the given topic.

Returns:



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/aws/auto_scaling/notification_configuration_collection.rb', line 109

def create options = {}
  
  topic_arn = options[:topic].is_a?(SNS::Topic) ? 
    options[:topic].arn : options[:topic]

  unless group = @group
    if group = options[:group]
      group = Group.new(group) unless group.is_a?(Group)
    else
      raise ArgumentError, 'missing required :group option'
    end
  end

  unless types = options[:types]
    types = AutoScaling.new(:config => config).notification_types
  end

  notification_config = NotificationConfiguration.new(group, topic_arn)
  notification_config.notification_types = types
  notification_config

end

#each {|notification_config| ... } ⇒ Object

Yields:

  • (notification_config)

Yield Parameters:



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/aws/auto_scaling/notification_configuration_collection.rb', line 135

def each &block

  #
  # <grumble> We can't use the standard pageable collection mixin here.
  # When you provide :max_records it returns each notification
  # type as an individual record, instead of notification configurations
  # with grouped types.  This makes it very possible to
  # get a part of a configuration in one page of results with the
  # rest in the next page.
  #
  # So instead we will request and group them all before yielding.
  # 

  next_token = nil

  groups = {}

  begin

    client_opts = {}
    client_opts[:next_token] = next_token if next_token
    client_opts[:auto_scaling_group_names] = [@group.name] if @group

    resp = client.describe_notification_configurations(client_opts)
    resp.notification_configurations.each do |c|
      group_name = c.auto_scaling_group_name
      groups[group_name] ||= {}
      groups[group_name][c.topic_arn] ||= []
      groups[group_name][c.topic_arn] << c.notification_type
    end

    next_token = resp.data[:next_token]

  end while next_token

  groups.each_pair do |group_name, topics|
    topics.each_pair do |topic_arn, types|
      
      notification_config = NotificationConfiguration.new(
        Group.new(group_name, :config => config), topic_arn, types)

      yield(notification_config)

    end
  end

end