Module: Jets::Job::Dsl::SnsEvent

Defined in:
lib/jets/job/dsl/sns_event.rb

Instance Method Summary collapse

Instance Method Details

#declare_sns_subscription(props = {}) ⇒ Object



36
37
38
39
40
41
# File 'lib/jets/job/dsl/sns_event.rb', line 36

def declare_sns_subscription(props={})
  r = Jets::Resource::Sns::Subscription.new(props)
  with_fresh_properties do
    resource(r.definition) # add associated resource immediately
  end
end

#declare_sns_topic(props = {}) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/jets/job/dsl/sns_event.rb', line 20

def declare_sns_topic(props={})
  props ||= {} # props.delete(:topic_properties) can be nil
  r = Jets::Resource::Sns::Topic.new(props)
  with_fresh_properties do
    resource(r.definition) # add associated resource immediately
  end
end

#declare_sns_topic_policy(props = {}) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/jets/job/dsl/sns_event.rb', line 28

def declare_sns_topic_policy(props={})
  props ||= {} # options.delete(:topic_policy_properties) can be nil
  r = Jets::Resource::Sns::TopicPolicy.new(props)
  with_fresh_properties do
    resource(r.definition) # add associated resource immediately
  end
end

#full_sns_topic_arn(topic_name) ⇒ Object

Expands simple topic name to full arn. Example:

hello-topic

To:

arn:aws:sns:us-west-2:112233445566:hello-topic


48
49
50
51
52
# File 'lib/jets/job/dsl/sns_event.rb', line 48

def full_sns_topic_arn(topic_name)
  return topic_name if topic_name.include?("arn:aws:sns")

  "arn:aws:sns:#{Jets.aws.region}:#{Jets.aws.}:#{topic_name}"
end

#sns_event(topic_name, props = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/jets/job/dsl/sns_event.rb', line 3

def sns_event(topic_name, props={})
  if topic_name.to_s =~ /generate/
    declare_sns_topic(props.delete(:topic_properties))
    topic_arn = "!Ref {namespace}SnsTopic"
    props.merge!(topic_arn: topic_arn)
    declare_sns_subscription(props)
  elsif topic_name.include?('!Ref') # reference shared resource
    topic_arn = topic_name # contains !Ref
    props.merge!(topic_arn: topic_arn)
    declare_sns_subscription(props)
  else # existing topic: short name or full arn
    topic_arn = full_sns_topic_arn(topic_name)
    props.merge!(topic_arn: topic_arn)
    declare_sns_subscription(props)
  end
end