-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsns.cfndsl.rb
80 lines (60 loc) · 2.13 KB
/
sns.cfndsl.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
CloudFormation do
default_tags = external_parameters.fetch(:default_tags, nil)
tags = []
default_tags.each do |key, value|
tags << {Key: key, Value: value}
end unless default_tags.nil?
topics = external_parameters.fetch(:topics, nil)
if (defined? topics and (not topics.nil?))
topics.each do |key, config|
config = {} if config.nil?
resource_name = "#{key.gsub('_', '').gsub('-', '').capitalize}"
SNS_Topic(resource_name) do
if config.key? 'topic_name'
TopicName config['topic_name']
end
if config.key? 'display_name'
DisplayName config['display_name']
end
if config.key? 'content_based_deduplication'
ContentBasedDeduplication config['content_based_deduplication']
end
if config.key? 'fifo_topic'
FifoTopic config['fifo_topic']
end
Tags tags unless tags.empty?
end
if config.key? 'subscriptions'
config['subscriptions'].each_with_index do |sub, ix|
SNS_Subscription("#{resource_name}s#{ix}") do
endpoint = sub['endpoint']
if sub['protocol'] == 'lambda'
if endpoint.include? '.' and endpoint.split('.').size == 2
endpoint = FnGetAtt(endpoint.split('.')[1], 'Arn')
elsif (not endpoint.start_with? 'arn:aws:lambda:')
# if arn is not given and not referencing lambda, we assume lambda is given as function name
# within same account and region
endpoint = FnJoin('', ['arn:aws:lambda:', Ref('AWS::Region'), ':', Ref('AWS::AccountId'), ':function:slackMessage'])
end
end
TopicArn Ref(resource_name)
Protocol sub['protocol']
Endpoint endpoint
end
end
end
if config.key? 'output' and config['output']
Output("Topic#{resource_name}Arn") do
Value Ref(resource_name)
end
end
end
else
SNS_Topic('DefaultTopic') do
Tags tags unless tags.empty?
end
Output('TopicDefaultArn') do
Value Ref('DefaultTopic')
end
end
end