Class: OpenStax::Aws::Alarm

Inherits:
Object
  • Object
show all
Defined in:
lib/openstax/aws/alarm.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(region:, name:) ⇒ Alarm

Returns a new instance of Alarm.



11
12
13
14
15
16
# File 'lib/openstax/aws/alarm.rb', line 11

def initialize(region:, name:)
  @raw_alarm = ::Aws::CloudWatch::Alarm.new(
    name: name,
    client: Aws::CloudWatch::Client.new(region: region)
  )
end

Instance Attribute Details

#raw_alarmObject (readonly)

Returns the value of attribute raw_alarm.



3
4
5
# File 'lib/openstax/aws/alarm.rb', line 3

def raw_alarm
  @raw_alarm
end

Class Method Details

.physical_resource_id_attributeObject



7
8
9
# File 'lib/openstax/aws/alarm.rb', line 7

def self.physical_resource_id_attribute
  :name
end

Instance Method Details

#add_tags_not_handled_by_cloudformation(stack_tags) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/openstax/aws/alarm.rb', line 30

def add_tags_not_handled_by_cloudformation(stack_tags)
  missing_tags = stack_tags.map(&:to_h) - tags.map(&:to_h)

  return if missing_tags.empty?

  logger.debug "Tagging #{name}..."
  attempt = 1
  begin
    tag_resource missing_tags
  rescue Aws::CloudWatch::Errors::Throttling
    retry_in = attempt**2
    logger.debug "Tagging #{name} failed... retrying in #{retry_in} seconds"
    sleep retry_in
    attempt += 1
    retry
  end
end

#loggerObject



26
27
28
# File 'lib/openstax/aws/alarm.rb', line 26

def logger
  OpenStax::Aws.configuration.logger
end

#tag_resource(new_tags) ⇒ Object



22
23
24
# File 'lib/openstax/aws/alarm.rb', line 22

def tag_resource(new_tags)
  client.tag_resource resource_arn: raw_alarm.alarm_arn, tags: new_tags
end

#tagsObject



18
19
20
# File 'lib/openstax/aws/alarm.rb', line 18

def tags
  client.list_tags_for_resource(resource_arn: raw_alarm.alarm_arn).tags
end