Class: CloudFormation::Bridge::Resources::SubscribeQueueToTopic

Inherits:
Base
  • Object
show all
Defined in:
lib/cloud_formation/bridge/resources/subscribe_queue_to_topic.rb

Constant Summary collapse

ARN =
'Arn'
TOPIC_ARN =
'TopicArn'
QUEUE_NAME =
'QueueName'
RAW_MESSAGE_DELIVERY =
'RawMessageDelivery'
REQUIRED_FIELDS =
[
  TOPIC_ARN,
  QUEUE_NAME,
]

Instance Method Summary collapse

Methods inherited from Base

#require_fields, #update, #wait_until

Instance Method Details

#create(request) ⇒ Object



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

def create(request)
  require_fields(request, REQUIRED_FIELDS)

  queue = queues.named(request.resource_properties[QUEUE_NAME])
  topic = topics[request.resource_properties[TOPIC_ARN]]

  subscription = topic.subscribe(queue)

  if request.resource_properties[RAW_MESSAGE_DELIVERY]
    subscription.raw_message_delivery = true
  end

  {
    FIELDS::PHYSICAL_RESOURCE_ID => subscription.arn,
    FIELDS::DATA => {
      ARN => subscription.arn,
    },
  }
end

#delete(request) ⇒ Object



42
43
44
45
# File 'lib/cloud_formation/bridge/resources/subscribe_queue_to_topic.rb', line 42

def delete(request)
  subscription = subscriptions[request.physical_resource_id]
  subscription.unsubscribe if subscription && subscription.exists?
end

#queuesObject



59
60
61
# File 'lib/cloud_formation/bridge/resources/subscribe_queue_to_topic.rb', line 59

def queues
  @queues ||= AWS::SQS.new.queues
end

#snsObject



55
56
57
# File 'lib/cloud_formation/bridge/resources/subscribe_queue_to_topic.rb', line 55

def sns
  @sns ||= AWS::SNS.new
end

#subscriptionsObject



51
52
53
# File 'lib/cloud_formation/bridge/resources/subscribe_queue_to_topic.rb', line 51

def subscriptions
  @subscriptions ||= sns.subscriptions
end

#topicsObject



47
48
49
# File 'lib/cloud_formation/bridge/resources/subscribe_queue_to_topic.rb', line 47

def topics
  @topics ||= sns.topics
end