-
Notifications
You must be signed in to change notification settings - Fork 0
/
cf_template.yml
426 lines (426 loc) · 14.1 KB
/
cf_template.yml
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
AWSTemplateFormatVersion: '2010-09-09'
Resources:
lf1:
Type: AWS::Lambda::Function
DeletionPolicy: Delete
Properties:
Runtime: python3.11
FunctionName: index-photos-cf
Handler: lambda_function.lambda_handler
Role: !GetAtt lf1Role.Arn
Code:
S3Bucket: ccbd-hw-2-lambdas
S3Key: LF1_deployment.zip
Timeout: 300
lf1Role:
Type: AWS::IAM::Role
DeletionPolicy: Delete
Properties:
RoleName: r-index-photos-cf
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
- arn:aws:iam::aws:policy/AmazonOpenSearchServiceFullAccess
- arn:aws:iam::aws:policy/AmazonRekognitionFullAccess
lf1Perm:
Type: AWS::Lambda::Permission
DeletionPolicy: Delete
Properties:
Action: lambda:InvokeFunction
FunctionName: !GetAtt lf1.Arn
Principal: s3.amazonaws.com
SourceAccount: 889594017971
SourceArn: !Sub arn:aws:s3:::${photoBucket}
lf2Role:
Type: AWS::IAM::Role
DeletionPolicy: Delete
Properties:
RoleName: r-search-photos-cf
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
- arn:aws:iam::aws:policy/AmazonOpenSearchServiceFullAccess
- arn:aws:iam::aws:policy/AmazonLexFullAccess
lf2Perm:
Type: AWS::Lambda::Permission
DeletionPolicy: Delete
Properties:
Action: lambda:InvokeFunction
FunctionName: !GetAtt lf2.Arn
Principal: apigateway.amazonaws.com
SourceArn: !Sub arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${gateway}/*/GET/search
lf2:
Type: AWS::Lambda::Function
DeletionPolicy: Delete
Properties:
Runtime: python3.11
FunctionName: search-photos-cf
Handler: lambda_function.lambda_handler
Role: !GetAtt lf2Role.Arn
Code:
S3Bucket: ccbd-hw-2-lambdas
S3Key: LF2_deployment.zip
Timeout: 300
frontendBucket:
Type: AWS::S3::Bucket
DeletionPolicy: Delete
Properties:
BucketName: hw2-frontend-us-east1-cf
PublicAccessBlockConfiguration:
BlockPublicAcls: false
BlockPublicPolicy: false
IgnorePublicAcls: false
RestrictPublicBuckets: false
WebsiteConfiguration:
IndexDocument: index.html
photoBucket:
Type: AWS::S3::Bucket
DeletionPolicy: Delete
Properties:
BucketName: hw2-photos-us-east1-cf
NotificationConfiguration:
LambdaConfigurations:
- Event: s3:ObjectCreated:Put
Function: !GetAtt lf1.Arn
PublicAccessBlockConfiguration:
BlockPublicAcls: false
BlockPublicPolicy: false
IgnorePublicAcls: false
RestrictPublicBuckets: false
photoBucketPolicy:
Type: 'AWS::S3::BucketPolicy'
DeletionPolicy: Delete
Properties:
Bucket: !Ref photoBucket
PolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: AllowPublicEverything
Effect: Allow
Principal: "*"
Action: s3:*
Resource:
- !Sub arn:aws:s3:::${photoBucket}
- !Sub arn:aws:s3:::${photoBucket}/*
frontendBucketPolicy:
Type: 'AWS::S3::BucketPolicy'
DeletionPolicy: Delete
Properties:
Bucket: !Ref frontendBucket
PolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: PublicReadGetObject
Effect: Allow
Principal: "*"
Action:
- s3:getObject
- s3:listBucket
Resource:
- !Sub arn:aws:s3:::${frontendBucket}
- !Sub arn:aws:s3:::${frontendBucket}/*
gatewayStage:
Type: AWS::ApiGateway::Stage
Properties:
RestApiId: !Ref gateway
StageName: dev2
DeploymentId: !Ref gatewayDeployment
gatewayDeployment:
Type: AWS::ApiGateway::Deployment
Properties:
RestApiId: !Ref gateway
gatewayRole:
Type: AWS::IAM::Role
DeletionPolicy: Delete
Properties:
RoleName: gateway-role
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: ''
Effect: Allow
Principal:
Service: apigateway.amazonaws.com
Action: sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs
- arn:aws:iam::aws:policy/AmazonS3FullAccess
gateway:
Type: AWS::ApiGateway::RestApi
DeletionPolicy: Delete
Properties:
Body:
swagger: "2.0"
info:
description: "AI Photo Search application, built during the Cloud and Big Data course\
\ at Columbia University."
version: "1.0.0"
title: "AI Photo Search"
host: "hk5v5cdowc.execute-api.us-east-1.amazonaws.com"
basePath: "/dev2"
schemes:
- "https"
paths:
/folder:
options:
consumes:
- "application/json"
responses:
"200":
description: "200 response"
headers:
Access-Control-Allow-Origin:
type: "string"
Access-Control-Allow-Methods:
type: "string"
Access-Control-Allow-Headers:
type: "string"
x-amazon-apigateway-integration:
responses:
default:
statusCode: "200"
responseParameters:
method.response.header.Access-Control-Allow-Methods: "'OPTIONS'"
method.response.header.Access-Control-Allow-Headers: "'*'"
method.response.header.Access-Control-Allow-Origin: "'*'"
requestTemplates:
application/json: "{\"statusCode\": 200}"
passthroughBehavior: "when_no_match"
type: "mock"
/folder/item:
put:
parameters:
- name: "customLabel"
in: "header"
required: false
type: "string"
- name: "object"
in: "query"
required: false
type: "string"
- name: "contentType"
in: "header"
required: false
type: "string"
- name: "bucket"
in: "query"
required: false
type: "string"
responses:
"200":
description: "200 response"
headers:
Access-Control-Allow-Origin:
type: "string"
x-amazon-apigateway-integration:
credentials: !GetAtt gatewayRole.Arn
httpMethod: "PUT"
uri: "arn:aws:apigateway:us-east-1:s3:path/{bucket}/{object}"
responses:
default:
statusCode: "200"
responseParameters:
method.response.header.Access-Control-Allow-Origin: "'*'"
requestParameters:
integration.request.path.object: "method.request.querystring.object"
integration.request.header.x-amz-meta-customLabels: "method.request.header.customLabel"
integration.request.path.bucket: "method.request.querystring.bucket"
integration.request.header.Content-Type: "method.request.header.contentType"
passthroughBehavior: "when_no_match"
contentHandling: "CONVERT_TO_BINARY"
type: "aws"
options:
consumes:
- "application/json"
- "text/plain"
parameters:
- name: "customLabel"
in: "header"
required: false
type: "string"
- name: "object"
in: "query"
required: false
type: "string"
- name: "contentType"
in: "header"
required: false
type: "string"
- name: "bucket"
in: "query"
required: false
type: "string"
responses:
"200":
description: "200 response"
headers:
Access-Control-Allow-Origin:
type: "string"
Access-Control-Allow-Methods:
type: "string"
Access-Control-Allow-Headers:
type: "string"
x-amazon-apigateway-integration:
responses:
default:
statusCode: "200"
responseParameters:
method.response.header.Access-Control-Allow-Methods: "'OPTIONS,PUT'"
method.response.header.Access-Control-Allow-Headers: "'*'"
method.response.header.Access-Control-Allow-Origin: "'*'"
requestTemplates:
application/json: "{ statusCode: 200 }"
text/plain: "{ statusCode: 200 }"
passthroughBehavior: "when_no_match"
type: "mock"
/search:
get:
operationId: "searchPhotos"
produces:
- "application/json"
parameters:
- name: "q"
in: "query"
required: false
type: "string"
responses:
"200":
description: "200 response"
schema:
$ref: "#/definitions/SearchResponse"
headers:
Access-Control-Allow-Origin:
type: "string"
"500":
description: "500 response"
schema:
$ref: "#/definitions/Error"
"403":
description: "403 response"
schema:
$ref: "#/definitions/Error"
x-amazon-apigateway-integration:
httpMethod: "POST"
uri: !Sub "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/${lf2.Arn}/invocations"
responses:
default:
statusCode: "200"
responseParameters:
method.response.header.Access-Control-Allow-Origin: "'*'"
passthroughBehavior: "when_no_match"
type: "aws_proxy"
options:
consumes:
- "application/json"
responses:
"200":
description: "200 response"
headers:
Access-Control-Allow-Origin:
type: "string"
Access-Control-Allow-Methods:
type: "string"
Access-Control-Allow-Headers:
type: "string"
x-amazon-apigateway-integration:
responses:
default:
statusCode: "200"
responseParameters:
method.response.header.Access-Control-Allow-Methods: "'GET,OPTIONS'"
method.response.header.Access-Control-Allow-Headers: "'*'"
method.response.header.Access-Control-Allow-Origin: "'*'"
requestTemplates:
application/json: "{\"statusCode\": 200}"
passthroughBehavior: "when_no_match"
type: "mock"
definitions:
Error:
type: "object"
properties:
code:
type: "integer"
format: "int32"
message:
type: "string"
Photo:
type: "object"
properties:
url:
type: "string"
labels:
type: "array"
items:
type: "string"
SearchResponse:
type: "object"
properties:
results:
type: "array"
items:
$ref: "#/definitions/Photo"
definitions:
Error:
type: "object"
properties:
code:
type: "integer"
format: "int32"
message:
type: "string"
Photo:
type: "object"
properties:
url:
type: "string"
labels:
type: "array"
items:
type: "string"
SearchResponse:
type: "object"
properties:
results:
type: "array"
items:
$ref: "#/definitions/Photo"
Name: cfApi
search:
Type: AWS::OpenSearchService::Domain
DeletionPolicy: Delete
Properties:
AccessPolicies:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
AWS: !Sub arn:aws:iam::889594017971:role/${lf1Role}
Action: 'es:*'
Resource: !Sub arn:aws:es:${AWS::Region}:${AWS::AccountId}:domain/photos-cf/*
DomainName: photos-cf
EBSOptions:
EBSEnabled: true
Iops: 0
VolumeSize: 20
VolumeType: gp2
ClusterConfig:
DedicatedMasterEnabled: false
InstanceCount: 2
ZoneAwarenessEnabled: true
InstanceType: t3.small.search