1
+ {
2
+ "Conditions" : {
3
+ "MyCondition" : {
4
+ "Fn::Equals" : [
5
+ true ,
6
+ false
7
+ ]
8
+ }
9
+ },
10
+ "Parameters" : {
11
+ "SnsRegion" : {
12
+ "Default" : " us-east-1" ,
13
+ "Type" : " String"
14
+ }
15
+ },
16
+ "Resources" : {
17
+ "Notifications" : {
18
+ "Type" : " AWS::SNS::Topic"
19
+ },
20
+ "SaveNotificationFunctionNotificationTopicQueue" : {
21
+ "Type" : " AWS::SQS::Queue" ,
22
+ "Properties" : {}
23
+ },
24
+ "SaveNotificationFunctionNotificationTopicQueuePolicy" : {
25
+ "Type" : " AWS::SQS::QueuePolicy" ,
26
+ "Properties" : {
27
+ "Queues" : [
28
+ {
29
+ "Ref" : " SaveNotificationFunctionNotificationTopicQueue"
30
+ }
31
+ ],
32
+ "PolicyDocument" : {
33
+ "Version" : " 2012-10-17" ,
34
+ "Statement" : [
35
+ {
36
+ "Action" : " sqs:SendMessage" ,
37
+ "Resource" : {
38
+ "Fn::GetAtt" : [
39
+ " SaveNotificationFunctionNotificationTopicQueue" ,
40
+ " Arn"
41
+ ]
42
+ },
43
+ "Effect" : " Allow" ,
44
+ "Condition" : {
45
+ "ArnEquals" : {
46
+ "aws:SourceArn" : {
47
+ "Ref" : " Notifications"
48
+ }
49
+ }
50
+ },
51
+ "Principal" : " *"
52
+ }
53
+ ]
54
+ }
55
+ }
56
+ },
57
+ "SaveNotificationFunctionNotificationTopic" : {
58
+ "Type" : " AWS::SNS::Subscription" ,
59
+ "Properties" : {
60
+ "FilterPolicy" : {
61
+ "Fn::If" : [
62
+ " MyCondition" ,
63
+ {
64
+ "price_usd" : [
65
+ {
66
+ "numeric" : [
67
+ " >=" ,
68
+ 100
69
+ ]
70
+ }
71
+ ]
72
+ },
73
+ {
74
+ "price_usd" : [
75
+ {
76
+ "numeric" : [
77
+ " <" ,
78
+ 100
79
+ ]
80
+ }
81
+ ]
82
+ }
83
+ ]
84
+ },
85
+ "Region" : {
86
+ "Ref" : " SnsRegion"
87
+ },
88
+ "Endpoint" : {
89
+ "Fn::GetAtt" : [
90
+ " SaveNotificationFunctionNotificationTopicQueue" ,
91
+ " Arn"
92
+ ]
93
+ },
94
+ "Protocol" : " sqs" ,
95
+ "TopicArn" : {
96
+ "Ref" : " Notifications"
97
+ }
98
+ }
99
+ },
100
+ "SaveNotificationFunctionRole" : {
101
+ "Type" : " AWS::IAM::Role" ,
102
+ "Properties" : {
103
+ "AssumeRolePolicyDocument" : {
104
+ "Version" : " 2012-10-17" ,
105
+ "Statement" : [
106
+ {
107
+ "Action" : [
108
+ " sts:AssumeRole"
109
+ ],
110
+ "Effect" : " Allow" ,
111
+ "Principal" : {
112
+ "Service" : [
113
+ " lambda.amazonaws.com"
114
+ ]
115
+ }
116
+ }
117
+ ]
118
+ },
119
+ "ManagedPolicyArns" : [
120
+ " arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ,
121
+ " arn:aws-cn:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole"
122
+ ],
123
+ "Tags" : [
124
+ {
125
+ "Value" : " SAM" ,
126
+ "Key" : " lambda:createdBy"
127
+ }
128
+ ]
129
+ }
130
+ },
131
+ "SaveNotificationFunctionNotificationTopicEventSourceMapping" : {
132
+ "Type" : " AWS::Lambda::EventSourceMapping" ,
133
+ "Properties" : {
134
+ "BatchSize" : 10 ,
135
+ "Enabled" : true ,
136
+ "FunctionName" : {
137
+ "Ref" : " SaveNotificationFunction"
138
+ },
139
+ "EventSourceArn" : {
140
+ "Fn::GetAtt" : [
141
+ " SaveNotificationFunctionNotificationTopicQueue" ,
142
+ " Arn"
143
+ ]
144
+ }
145
+ }
146
+ },
147
+ "SaveNotificationFunction" : {
148
+ "Type" : " AWS::Lambda::Function" ,
149
+ "Properties" : {
150
+ "Handler" : " index.save_notification" ,
151
+ "Code" : {
152
+ "S3Bucket" : " sam-demo-bucket" ,
153
+ "S3Key" : " notifications.zip"
154
+ },
155
+ "Role" : {
156
+ "Fn::GetAtt" : [
157
+ " SaveNotificationFunctionRole" ,
158
+ " Arn"
159
+ ]
160
+ },
161
+ "Runtime" : " nodejs12.x" ,
162
+ "Tags" : [
163
+ {
164
+ "Value" : " SAM" ,
165
+ "Key" : " lambda:createdBy"
166
+ }
167
+ ]
168
+ }
169
+ }
170
+ }
171
+ }
0 commit comments