-
Notifications
You must be signed in to change notification settings - Fork 262
/
SNSToSQS.template
211 lines (207 loc) · 6.27 KB
/
SNSToSQS.template
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "This Template creates an SNS topic that can send messages to two SQS queues with appropriate permissions for one IAM user to publish to the topic and another to read messages from the queues. MySNSTopic is set up to publish to two subscribed endpoints, which are two SQS queues (MyQueue1 and MyQueue2). MyPublishUser is an IAM user that can publish to MySNSTopic using the Publish API. MyTopicPolicy assigns that permission to MyPublishUser. MyQueueUser is an IAM user that can read messages from the two SQS queues. MyQueuePolicy assigns those permissions to MyQueueUser. It also assigns permission for MySNSTopic to publish its notifications to the two queues. The template creates access keys for the two IAM users with MyPublishUserKey and MyQueueUserKey. Note that you will be billed for the AWS resources used if you create a stack from this template.",
"Parameters" : {
"MyPublishUserPassword": {
"NoEcho": "true",
"Type": "String",
"Description" : "Password for the IAM user MyPublishUser",
"MinLength": "1",
"MaxLength": "41",
"AllowedPattern" : "[a-zA-Z0-9]*",
"ConstraintDescription" : "must contain only alphanumeric characters."
},
"MyQueueUserPassword": {
"NoEcho": "true",
"Type": "String",
"Description" : "Password for the IAM user MyQueueUser",
"MinLength": "1",
"MaxLength": "41",
"AllowedPattern" : "[a-zA-Z0-9]*",
"ConstraintDescription" : "must contain only alphanumeric characters."
}
},
"Resources" : {
"MySNSTopic" : {
"Type" : "AWS::SNS::Topic",
"Properties" : {
"Subscription" : [
{
"Endpoint" : { "Fn::GetAtt" : ["MyQueue1", "Arn"]},
"Protocol" : "sqs"
},
{
"Endpoint" : { "Fn::GetAtt" : ["MyQueue2", "Arn"]},
"Protocol" : "sqs"
}
]
}
},
"MyQueue1" : {
"Type" : "AWS::SQS::Queue"
},
"MyQueue2" : {
"Type" : "AWS::SQS::Queue"
},
"MyPublishUser" : {
"Type" : "AWS::IAM::User",
"Properties" : {
"LoginProfile": {
"Password": {"Ref" : "MyPublishUserPassword"}
}
}
},
"MyPublishUserKey" : {
"Type" : "AWS::IAM::AccessKey",
"Properties" : {
"UserName" : {"Ref": "MyPublishUser"}
}
},
"MyPublishTopicGroup" : {
"Type" : "AWS::IAM::Group",
"Properties" : {
"Policies": [
{
"PolicyName": "MyTopicGroupPolicy",
"PolicyDocument": {"Statement":[
{
"Effect":"Allow",
"Action":[
"sns:Publish"
],
"Resource": {"Ref" : "MySNSTopic"}
}
]}
}
]
}
},
"AddUserToMyPublishTopicGroup" : {
"Type" : "AWS::IAM::UserToGroupAddition",
"Properties" : {
"GroupName": {"Ref" : "MyPublishTopicGroup"},
"Users" : [{ "Ref" : "MyPublishUser" }]
}
},
"MyQueueUser" : {
"Type" : "AWS::IAM::User",
"Properties" : {
"LoginProfile": {
"Password": {"Ref" : "MyQueueUserPassword"}
}
}
},
"MyQueueUserKey" : {
"Type" : "AWS::IAM::AccessKey",
"Properties" : {
"UserName" : {"Ref": "MyQueueUser"}
}
},
"MyRDMessageQueueGroup" : {
"Type" : "AWS::IAM::Group",
"Properties" : {
"Policies": [
{
"PolicyName": "MyQueueGroupPolicy",
"PolicyDocument": {"Statement":[
{
"Effect":"Allow",
"Action":[
"sqs:DeleteMessage",
"sqs:ReceiveMessage"
],
"Resource":[
{ "Fn::GetAtt" : ["MyQueue1", "Arn"]},
{ "Fn::GetAtt" : ["MyQueue2", "Arn"]}
]
}
]}
}
]
}
},
"AddUserToMyQueueGroup" : {
"Type" : "AWS::IAM::UserToGroupAddition",
"Properties" : {
"GroupName": {"Ref" : "MyRDMessageQueueGroup"},
"Users" : [{ "Ref" : "MyQueueUser" }]
}
},
"MyQueuePolicy" : {
"Type" : "AWS::SQS::QueuePolicy",
"Properties" : {
"PolicyDocument": {
"Id":"MyQueuePolicy",
"Statement" : [
{
"Sid":"Allow-SendMessage-To-Both-Queues-From-SNS-Topic",
"Effect":"Allow",
"Principal" : {"AWS" : "*"},
"Action":["sqs:SendMessage"],
"Resource": "*",
"Condition": {
"ArnEquals": {
"aws:SourceArn": { "Ref" : "MySNSTopic" }
}
}
}
]
},
"Queues" : [{"Ref" : "MyQueue1"}, {"Ref" : "MyQueue2"}]
}
}
},
"Outputs" : {
"MySNSTopicTopicARN" : {
"Value" : { "Ref" : "MySNSTopic" }
},
"MyQueue1Info" : {
"Value" : {"Fn::Join" : [
" ",
[
"ARN:",
{ "Fn::GetAtt" : [ "MyQueue1", "Arn" ] },
"URL:",
{ "Ref" : "MyQueue1" }
]
]}
},
"MyQueue2Info" : {
"Value" : {"Fn::Join" : [
" ",
[
"ARN:",
{ "Fn::GetAtt" : [ "MyQueue2", "Arn" ] },
"URL:",
{ "Ref" : "MyQueue2" }
]
]}
},
"MyPublishUserInfo" : {
"Value" : {"Fn::Join" : [
" ",
[
"ARN:",
{ "Fn::GetAtt" : [ "MyPublishUser", "Arn" ] },
"Access Key:",
{"Ref" : "MyPublishUserKey"},
"Secret Key:",
{"Fn::GetAtt" : ["MyPublishUserKey", "SecretAccessKey"]}
]
]}
},
"MyQueueUserInfo" : {
"Value" : {"Fn::Join" : [
" ",
[
"ARN:",
{ "Fn::GetAtt" : [ "MyQueueUser", "Arn" ] },
"Access Key:",
{"Ref" : "MyQueueUserKey"},
"Secret Key:",
{"Fn::GetAtt" : ["MyQueueUserKey", "SecretAccessKey"]}
]
]}
}
}
}