Class: Bauble::Resources::SQSQueue

Inherits:
Resource
  • Object
show all
Defined in:
lib/bauble/resources/sqs_queue.rb

Overview

SQS Queue

Instance Attribute Summary collapse

Attributes inherited from Resource

#app

Instance Method Summary collapse

Methods inherited from Resource

#resource_name

Constructor Details

#initialize(app, **kwargs) ⇒ SQSQueue

Returns a new instance of SQSQueue.



13
14
15
16
17
18
19
20
21
# File 'lib/bauble/resources/sqs_queue.rb', line 13

def initialize(app, **kwargs)
  super(app)
  @name = kwargs.fetch(:name)
  @visibility_timeout = kwargs.fetch(:visibility_timeout, 30)
  @message_retention = kwargs.fetch(:message_retention, 345_600)
  @dead_letter_queue = kwargs.fetch(:dead_letter_queue, nil)
  @content_based_deduplication = kwargs.fetch(:content_based_deduplication, false)
  @lambda_targets = []
end

Instance Attribute Details

#dead_letter_queueObject

Returns the value of attribute dead_letter_queue.



10
11
12
# File 'lib/bauble/resources/sqs_queue.rb', line 10

def dead_letter_queue
  @dead_letter_queue
end

#encryptionObject

Returns the value of attribute encryption.



10
11
12
# File 'lib/bauble/resources/sqs_queue.rb', line 10

def encryption
  @encryption
end

#encryption_master_keyObject

Returns the value of attribute encryption_master_key.



10
11
12
# File 'lib/bauble/resources/sqs_queue.rb', line 10

def encryption_master_key
  @encryption_master_key
end

#lambda_targetsObject

Returns the value of attribute lambda_targets.



10
11
12
# File 'lib/bauble/resources/sqs_queue.rb', line 10

def lambda_targets
  @lambda_targets
end

#message_retentionObject

Returns the value of attribute message_retention.



10
11
12
# File 'lib/bauble/resources/sqs_queue.rb', line 10

def message_retention
  @message_retention
end

#nameObject

Returns the value of attribute name.



10
11
12
# File 'lib/bauble/resources/sqs_queue.rb', line 10

def name
  @name
end

#visibility_timeoutObject

Returns the value of attribute visibility_timeout.



10
11
12
# File 'lib/bauble/resources/sqs_queue.rb', line 10

def visibility_timeout
  @visibility_timeout
end

Instance Method Details

#add_target(function) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/bauble/resources/sqs_queue.rb', line 46

def add_target(function)
  @lambda_targets << {
    "#{@name}_to_#{function.name}" => {
      'type' => 'aws:lambda:EventSourceMapping',
      'properties' => {
        'eventSourceArn' => "${#{name}.arn}",
        'functionName' => "${#{function.name}.name}",
        'batchSize' => 10
      }
    }
  }
  function.role.add_policy_statement(
    effect: 'Allow',
    actions: ['sqs:ReceiveMessage', 'sqs:DeleteMessage', 'sqs:GetQueueAttributes'],
    resources: ["${#{name}.arn}"]
  )
end

#bundleObject



42
43
44
# File 'lib/bauble/resources/sqs_queue.rb', line 42

def bundle
  true
end

#synthesizeObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/bauble/resources/sqs_queue.rb', line 23

def synthesize
  base_template = {
    @name => {
      'type' => 'aws:sqs:Queue',
      'properties' => {
        'name' => resource_name(@name),
        'visibilityTimeoutSeconds' => @visibility_timeout,
        'messageRetentionSeconds' => @message_retention
      }.compact
    }
  }

  base_template.merge!(dead_letter_queue_template) if @dead_letter_queue

  @lambda_targets.each { |target| base_template.merge!(target) }

  base_template
end