-
Notifications
You must be signed in to change notification settings - Fork 2
/
template.yaml
226 lines (206 loc) · 9.86 KB
/
template.yaml
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Globals: # More info about Globals: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification-template-anatomy-globals.html
Function:
Timeout: 20
Resources:
#########################################
### ANTI-CORRUPTION-SERVICE RESOURCES ###
#########################################
JobEventsTopic:
Type: AWS::SNS::Topic # More info about SNS Resource: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-sns-topic.html
Properties:
TopicName: JobEvents.fifo
FifoTopic: true
ContentBasedDeduplication: false
AntiCorruptionFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html
Properties:
CodeUri: anti-corruption-service/
Handler: app.lambda_handler
Runtime: python3.9
MemorySize: 256
Environment:
Variables:
TOPIC_ARN: !Ref JobEventsTopic
Policies:
- SNSPublishMessagePolicy: # https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-policy-template-list.html#sqs-publish-message-policy
TopicName: !GetAtt JobEventsTopic.TopicName
Events:
Trigger:
Type: Schedule # More info about Schedule Event Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-function-schedule.html
Properties:
Schedule: 'rate(1 minute)'
###################################
### ANALYTICS-SERVICE RESOURCES ###
###################################
AnalyticsJobEventsQueue:
Type: AWS::SQS::Queue # More info about SQS Resource: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-sqs-queues.html
Properties:
QueueName: AnalyticsJobEvents.fifo
FifoQueue: true
RedrivePolicy:
deadLetterTargetArn: !GetAtt AnalyticsJobEventsQueueDLQ.Arn
maxReceiveCount: 3
AnalyticsJobEventsQueueDLQ:
Type: AWS::SQS::Queue # More info about SQS Resource: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-sqs-queues.html
Properties:
QueueName: AnalyticsJobEventsDLQ.fifo
FifoQueue: true
AnalyticsJobEventsSubscriptionDLQ:
Type: AWS::SQS::Queue # More info about SQS Resource: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-sqs-queues.html
Properties:
QueueName: AnalyticsSubscriptionDLQ.fifo
FifoQueue: true
AnalyticsFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html
Properties:
CodeUri: analytics-service/
Handler: app.lambda_handler
Runtime: python3.9
MemorySize: 256
Environment:
Variables:
BUCKET_NAME: !Ref AnalyticsBucket
Policies:
- S3WritePolicy: # https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-policy-template-list.html#s3-write-policy
BucketName: !Ref AnalyticsBucket
Events:
Trigger:
Type: SQS # More info about SQS Event Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-function-sqs.html
Properties:
Queue: !GetAtt AnalyticsJobEventsQueue.Arn
BatchSize: 10
AnalyticsBucket:
Type: AWS::S3::Bucket # More info about S3 Resource: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket.html
AnalyticsJobEventsQueuePolicy:
Type: AWS::SQS::QueuePolicy # More info about SQS Queue Policy Resource: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-sqs-policy.html
Properties:
Queues:
- !Ref AnalyticsJobEventsQueue
- !Ref AnalyticsJobEventsSubscriptionDLQ
PolicyDocument:
Statement:
Effect: Allow
Principal: '*'
Action: sqs:SendMessage
Resource: '*'
Condition:
ArnEquals:
aws:SourceArn: !Ref JobEventsTopic
AnalyticsJobEventsQueueToJobEventsTopicSubscription:
Type: AWS::SNS::Subscription # More info about SNS Topic Subscription Resource: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-sns-subscription.html
Properties:
Endpoint: !GetAtt AnalyticsJobEventsQueue.Arn
Protocol: sqs
RawMessageDelivery: true
TopicArn: !Ref JobEventsTopic
RedrivePolicy: !Sub '{"deadLetterTargetArn": "${AnalyticsJobEventsSubscriptionDLQ.Arn}"}'
###################################
### INVENTORY SERVICE RESOURCES ###
###################################
InventoryJobEventsQueue:
Type: AWS::SQS::Queue # More info about SQS Resource: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-sqs-queues.html
Properties:
QueueName: InventoryJobEvents.fifo
FifoQueue: true
RedrivePolicy:
deadLetterTargetArn: !GetAtt InventoryJobEventsQueueDLQ.Arn
maxReceiveCount: 3
InventoryJobEventsQueueDLQ:
Type: AWS::SQS::Queue # More info about SQS Resource: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-sqs-queues.html
Properties:
QueueName: InventoryJobEventsDLQ.fifo
FifoQueue: true
InventoryJobEventsQueueSubscriptionDLQ:
Type: AWS::SQS::Queue # More info about SQS Resource: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-sqs-queues.html
Properties:
QueueName: InventorySubscriptionDLQ.fifo
FifoQueue: true
InventoryFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html
Properties:
CodeUri: inventory-service/
Handler: app.lambda_handler
Runtime: python3.9
MemorySize: 256
Environment:
Variables:
TABLE_NAME: !Ref InventoryTable
Policies:
- DynamoDBCrudPolicy: # https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-policy-template-list.html#dynamo-db-crud-policy
TableName: !Ref InventoryTable
Events:
Trigger:
Type: SQS # More info about SQS Event Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-function-sqs.html
Properties:
Queue: !GetAtt InventoryJobEventsQueue.Arn
BatchSize: 10
InventoryTable:
Type: AWS::Serverless::SimpleTable # More info about SimpleTable Resource: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-simpletable.html
Properties:
TableName: InventoryTable
PrimaryKey:
Name: id
Type: String
InventoryJobEventsQueuePolicy:
Type: AWS::SQS::QueuePolicy # More info about SQS Queue Policy Resource: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-sqs-policy.html
Properties:
Queues:
- !Ref InventoryJobEventsQueue
- !Ref InventoryJobEventsQueueSubscriptionDLQ
PolicyDocument:
Statement:
Effect: Allow
Principal: '*'
Action: sqs:SendMessage
Resource: '*'
Condition:
ArnEquals:
aws:SourceArn: !Ref JobEventsTopic
InventoryJobEventsQueueToJobEventsTopicSubscription:
Type: AWS::SNS::Subscription # More info about SNS Topic Subscription Resource: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-sns-subscription.html
Properties:
Endpoint: !GetAtt InventoryJobEventsQueue.Arn
Protocol: sqs
RawMessageDelivery: true
TopicArn: !Ref JobEventsTopic
FilterPolicy: '{"eventType":["JobCreated", "JobDeleted"]}'
RedrivePolicy: !Sub '{"deadLetterTargetArn": "${InventoryJobEventsQueueSubscriptionDLQ.Arn}"}'
Outputs:
AntiCorruptionFunction:
Description: "AWS Lambda function ARN for the anti-corruption service"
Value: !GetAtt AntiCorruptionFunction.Arn
JobEventsTopic:
Description: "Amazon SNS topic ARN for the anti-corruption service job events topic"
Value: !Ref JobEventsTopic
AnalyticsFunction:
Description: "AWS Lambda function ARN for the analytics service"
Value: !GetAtt AnalyticsFunction.Arn
AnalyticsBucket:
Description: "Amazon S3 bucket name for the analytics service job events bucket"
Value: !Ref AnalyticsBucket
AnalyticsJobEventsQueueDLQ:
Description: "Amazon SQS queue ARN for the analytics service job events DLQ"
Value: !GetAtt AnalyticsJobEventsQueueDLQ.Arn
AnalyticsJobEventsSubscriptionDLQ:
Description: "Amazon SQS queue ARN for the analytics service job events subscription DLQ"
Value: !GetAtt AnalyticsJobEventsSubscriptionDLQ.Arn
AnalyticsJobEventsQueue:
Description: "Amazon SQS queue ARN for the analytics service job events queue"
Value: !GetAtt AnalyticsJobEventsQueue.Arn
InventoryFunction:
Description: "AWS Lambda function ARN for the inventory service"
Value: !GetAtt InventoryFunction.Arn
InventoryTable:
Description: "Amazon DynamoDB table name for the job events in the inventory service"
Value: !Ref InventoryTable
InventoryJobEventsQueueDLQ:
Description: "Amazon SQS queue ARN for the inventory service job events DLQ"
Value: !GetAtt InventoryJobEventsQueueDLQ.Arn
InventoryJobEventsQueueSubscriptionDLQ:
Description: "Amazon SQS queue ARN for the inventory service job events subscription DLQ"
Value: !GetAtt InventoryJobEventsQueueSubscriptionDLQ.Arn
InventoryJobEventsQueue:
Description: "Amazon SQS queue ARN for the inventory service job events queue"
Value: !GetAtt InventoryJobEventsQueue.Arn