-
Notifications
You must be signed in to change notification settings - Fork 138
/
template.yaml
256 lines (237 loc) · 6.21 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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: patterns-s3-docrepo
Parameters:
DocumentsBucketName:
Type: String
Default: 'patterns-s3docrepo-documents'
StagingBucketName:
Type: String
Default: 'patterns-s3docrepo-staging'
QueuedBucketName:
Type: String
Default: 'patterns-s3docrepo-queued'
ESdomain:
Type: String
Default: '<<YOUR-ENDPOINT-HERE>>'
Globals:
Function:
Timeout: 15
Environment:
Variables:
language: 'en'
Resources:
## S3 buckets
DocumentsBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Ref DocumentsBucketName
StagingBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Ref StagingBucketName
QueuedBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Ref QueuedBucketName
## SQS queue
MySqsQueue:
Type: AWS::SQS::Queue
# Lambda functions
queryESFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: queryESindex/
Handler: app.handler
Runtime: nodejs12.x
MemorySize: 128
Timeout: 10
ReservedConcurrentExecutions: 1
Environment:
Variables:
domain: !Ref ESdomain
Events:
HttpApiEvent:
Type: HttpApi
Properties:
Path: /
Method: GET
AddToESFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: addToESindex/
Handler: app.handler
Runtime: nodejs12.x
MemorySize: 128
Timeout: 10
ReservedConcurrentExecutions: 1
Environment:
Variables:
domain: !Ref ESdomain
Policies:
- S3ReadPolicy:
BucketName: !Ref QueuedBucketName
- Statement:
- Effect: Allow
Resource: '*'
Action:
- comprehend:*
Events:
MySQSEvent:
Type: SQS
Properties:
Queue: !GetAtt MySqsQueue.Arn
BatchSize: 1
BatchingFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: batchingFunction/
Handler: app.handler
Runtime: nodejs12.x
MemorySize: 512
Environment:
Variables:
OutputBucket: !Ref QueuedBucketName
Policies:
- S3CrudPolicy:
BucketName: !Ref QueuedBucketName
- S3ReadPolicy:
BucketName: !Ref StagingBucketName
Events:
OriginalTextUpload:
Type: S3
Properties:
Bucket: !Ref StagingBucket
Events: s3:ObjectCreated:*
Filter:
S3Key:
Rules:
- Name: suffix
Value: '.txt'
AddToQueueFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: addToQueueFunction/
Handler: app.handler
Runtime: nodejs12.x
Timeout: 15
MemorySize: 128
Environment:
Variables:
SQSqueueName: !Ref MySqsQueue
Policies:
- SQSSendMessagePolicy:
QueueName: !GetAtt MySqsQueue.QueueName
- S3ReadPolicy:
BucketName: !Ref QueuedBucketName
Events:
FileUpload:
Type: S3
Properties:
Bucket: !Ref QueuedBucket
Events: s3:ObjectCreated:*
ProcessJPGFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: processJPG/
Handler: app.handler
Runtime: nodejs12.x
MemorySize: 128
Environment:
Variables:
OutputBucket: !Ref QueuedBucketName
MaxLabels: 5
MinConfidence: 60
Policies:
- S3CrudPolicy:
BucketName: !Ref QueuedBucketName
- S3ReadPolicy:
BucketName: !Ref DocumentsBucketName
- Statement:
- Effect: Allow
Resource: '*'
Action:
- rekognition:*
Events:
Upload:
Type: S3
Properties:
Bucket: !Ref DocumentsBucket
Events: s3:ObjectCreated:*
Filter:
S3Key:
Rules:
- Name: suffix
Value: '.jpg'
ProcessDOCXFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: processDOCX/
Handler: app.handler
Runtime: nodejs12.x
MemorySize: 512
Environment:
Variables:
OutputBucket: !Ref StagingBucketName
Policies:
- S3CrudPolicy:
BucketName: !Ref StagingBucketName
- S3ReadPolicy:
BucketName: !Ref DocumentsBucketName
Events:
Upload:
Type: S3
Properties:
Bucket: !Ref DocumentsBucket
Events: s3:ObjectCreated:*
Filter:
S3Key:
Rules:
- Name: suffix
Value: '.docx'
ProcessPDFFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: processPDF/
Handler: app.handler
Runtime: nodejs12.x
MemorySize: 512
Environment:
Variables:
OutputBucket: !Ref StagingBucketName
Policies:
- S3CrudPolicy:
BucketName: !Ref StagingBucketName
- S3ReadPolicy:
BucketName: !Ref DocumentsBucketName
Events:
Upload:
Type: S3
Properties:
Bucket: !Ref DocumentsBucket
Events: s3:ObjectCreated:*
Filter:
S3Key:
Rules:
- Name: suffix
Value: '.pdf'
## Outputs
Outputs:
DocumentsBucketName:
Description: Documents Bucket Name
Value: !Ref DocumentsBucket
StagingBucketName:
Description: Staging Bucket Name
Value: !Ref StagingBucket
QueuedBucketName:
Description: Queued Bucket Name
Value: !Ref QueuedBucket
AddToESFunctionARN:
Description: This AddToESFunction function ARN.
Value: !GetAtt AddToESFunction.Arn
AddToESFunctionRoleARN:
Description: This ARN needs permission in the Elasticsearch configuration.
Value: !GetAtt AddToESFunctionRole.Arn
queryESFunctionARN:
Description: This ARN needs permission in the Elasticsearch configuration.
Value: !GetAtt queryESFunction.Arn