-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yaml
1148 lines (1141 loc) · 35.3 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
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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Build and Deploy Template for DC API
#
# Note: Any comment starting with `#*` will be removed
# at build time. This allows us to run without the
# dependency layer in development without removing the
# layer from the build.
AWSTemplateFormatVersion: "2010-09-09"
Transform:
- AWS::Serverless-2016-10-31
- AWS::LanguageExtensions
Description: >
dc-api-v2
SAM Template for dc-api-v2
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
CodeUri: ./node/src
Runtime: nodejs20.x
Architectures:
- x86_64
MemorySize: 128
Timeout: 10
Environment:
Variables:
API_TOKEN_NAME: !Ref ApiTokenName
API_TOKEN_SECRET: !Ref ApiTokenSecret
DC_API_ENDPOINT: !Ref DcApiEndpoint
DC_URL: !Ref DcUrl
DEV_TEAM_NET_IDS: !Ref DevTeamNetIds
ENV_PREFIX: !Ref EnvironmentPrefix
HONEYBADGER_API_KEY: !Ref HoneybadgerApiKey
HONEYBADGER_ENV: !Ref HoneybadgerEnv
HONEYBADGER_REVISION: !Ref HoneybadgerRevision
READING_ROOM_IPS: !Ref ReadingRoomIPs
SECRETS_PATH: !Ref SecretsPath
Parameters:
ApiTokenName:
Type: String
Description: Name of the jwt that DC API issues
ApiTokenSecret:
Type: String
Description: Secret Key for Encrypting JWTs (must match IIIF server)
CustomDomainCertificateArn:
Type: String
Description: SSL Certificate for the Custom Domain Name
CustomDomainZone:
Type: String
Description: Hosted Zone Name for Custom Domain
CustomDomainHost:
Type: String
Description: Hostname within ApiDomainName for Custom Domain
DcApiEndpoint:
Type: String
Description: URL for DC API
DcUrl:
Type: String
Description: URL of Digital Collections website
DevTeamNetIds:
Type: String
Description: Northwestern NetIDs of the development team
FfmpegLayer:
Type: String
Description: "FFMPEG Lambda Layer ARN"
Default: "arn:aws:lambda:us-east-1:625046682746:layer:ffmpeg:11"
EnvironmentPrefix:
Type: String
Description: Index Prefix
Default: ""
HoneybadgerApiKey:
Type: String
Description: Honeybadger API Key
Default: ""
HoneybadgerEnv:
Type: String
Description: Honeybadger Environment
Default: ""
HoneybadgerRevision:
Type: String
Description: Honeybadger Revision
Default: ""
MediaConvertDestinationBucket:
Type: String
Description: S3 bucket destination for transcoded AV resource
Default: ""
MediaConvertEndpoint:
Type: String
Description: MediaConvert endpoint
Default: ""
MediaConvertJobQueueArn:
Type: String
Description: Job Queue ARN for MediaConvert
Default: ""
MediaConvertRoleArn:
Type: String
Description: MediaConvert role ARN
Default: ""
PyramidBucket:
Type: String
Description: Meadow Pyramid Bucket
ReadingRoomIPs:
Type: String
Description: Comma-delimited list of IP addresses to serve private resources to
RepositoryEmail:
Type: String
Description: Verified email address to use as sender
SecretsPath:
Type: String
Description: Prefix to use when loading configs from Secrets Manager
StreamingBucket:
Type: String
Description: Meadow Streaming Bucket
Resources:
apiDependencies:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: !Sub "${AWS::StackName}-api-dependencies"
Description: Dependencies for API handlers
ContentUri: ./layers/api_dependencies
CompatibleRuntimes:
- nodejs20.x
LicenseInfo: Apache-2.0
Metadata:
BuildMethod: nodejs20.x
# Configuration
apiConfiguration:
Type: AWS::SecretsManager::Secret
Properties:
Name: !Sub "${SecretsPath}/config/dcapi"
SecretString:
Fn::ToJsonString:
api_token_secret: !Ref ApiTokenSecret
base_url: !Sub "https://${CustomDomainHost}.${CustomDomainZone}/api/v2"
readSecretsPolicy:
Type: AWS::IAM::ManagedPolicy
Properties:
PolicyDocument:
Version: 2012-10-17
Statement:
- Sid: GetSecrets
Effect: Allow
Action:
- secretsmanager:GetSecretValue
Resource: !Sub "arn:aws:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:${SecretsPath}/*"
- Sid: BatchGetSecrets
Effect: Allow
Action:
- secretsmanager:BatchGetSecretValue
Resource: "*"
readIndexPolicy:
Type: AWS::IAM::ManagedPolicy
Properties:
PolicyDocument:
Version: 2012-10-17
Statement:
- Sid: ESHTTPPolicy
Effect: Allow
Action:
- es:ESHttp*
Resource: "*"
# V2 API
getAuthCallbackFunction:
Type: AWS::Serverless::Function
Properties:
Handler: handlers/get-auth-callback.handler
Description: NUSSO callback function.
Layers:
- !Ref apiDependencies
Policies:
- !Ref readSecretsPolicy
Events:
ApiGet:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /auth/callback
Method: GET
ApiHead:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /auth/callback
Method: HEAD
getAuthLoginFunction:
Type: AWS::Serverless::Function
Properties:
Handler: handlers/get-auth-login.handler
Description: Performs NUSSO login.
Layers:
- !Ref apiDependencies
Policies:
- !Ref readSecretsPolicy
Events:
ApiGet:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /auth/login
Method: GET
getAuthLogoutFunction:
Type: AWS::Serverless::Function
Properties:
Handler: handlers/get-auth-logout.handler
Description: Performs NUSSO logout.
Layers:
- !Ref apiDependencies
Policies:
- !Ref readSecretsPolicy
Events:
ApiGet:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /auth/logout
Method: GET
getAuthTokenFunction:
Type: AWS::Serverless::Function
Properties:
Handler: handlers/get-auth-token.handler
Description: Function to retrieve raw JWT.
Layers:
- !Ref apiDependencies
Policies:
- !Ref readSecretsPolicy
Events:
ApiGet:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /auth/token
Method: GET
ApiHead:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /auth/token
Method: HEAD
getAuthWhoAmIFunction:
Type: AWS::Serverless::Function
Properties:
Handler: handlers/get-auth-whoami.handler
Description: Exchanges valid JWT token for user information.
Layers:
- !Ref apiDependencies
Policies:
- !Ref readSecretsPolicy
Events:
ApiGet:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /auth/whoami
Method: GET
getCollectionsFunction:
Type: AWS::Serverless::Function
Properties:
Handler: handlers/get-collections.handler
Description: Gets Collections.
Layers:
- !Ref apiDependencies
Policies:
- !Ref readSecretsPolicy
- !Ref readIndexPolicy
Events:
ApiGet:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /collections
Method: GET
ApiHead:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /collections
Method: HEAD
getCollectionByIdFunction:
Type: AWS::Serverless::Function
Properties:
Handler: handlers/get-collection-by-id.handler
Description: Gets a Collection by id.
Layers:
- !Ref apiDependencies
Policies:
- !Ref readSecretsPolicy
- !Ref readIndexPolicy
Events:
ApiGet:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /collections/{id}
Method: GET
ApiHead:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /collections/{id}
Method: HEAD
getFileSetByIdFunction:
Type: AWS::Serverless::Function
Properties:
Handler: handlers/get-file-set-by-id.handler
Description: Gets a FileSet by id.
Layers:
- !Ref apiDependencies
Policies:
- !Ref readSecretsPolicy
- !Ref readIndexPolicy
Events:
ApiGet:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /file-sets/{id}
Method: GET
ApiHead:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /file-sets/{id}
Method: HEAD
getFileSetAuthFunction:
Type: AWS::Serverless::Function
Properties:
Handler: handlers/get-file-set-auth.handler
Description: Authorizes access to a file set.
Layers:
- !Ref apiDependencies
Environment:
Variables:
USE_PROXIED_IP: true
Policies:
- !Ref readSecretsPolicy
- !Ref readIndexPolicy
Events:
ApiGet:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /file-sets/{id}/authorization
Method: GET
ApiHead:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /file-sets/{id}/authorization
Method: HEAD
getFileSetDownloadFunction:
Type: AWS::Serverless::Function
Properties:
Handler: handlers/get-file-set-download.handler
Description: Downloads a file set.
Layers:
- !Ref apiDependencies
Environment:
Variables:
STEP_FUNCTION_ENDPOINT: !Ref AWS::NoValue
AV_DOWNLOAD_STATE_MACHINE_ARN: !Ref avDownloadStateMachine
AV_DOWNLOAD_EMAIL_TEMPLATE: !Ref avDownloadEmailTemplate
USE_PROXIED_IP: true
STREAMING_BUCKET: !Ref StreamingBucket
MEDIA_CONVERT_DESTINATION_BUCKET: !Ref MediaConvertDestinationBucket
MEDIA_CONVERT_ENDPOINT: !Ref MediaConvertEndpoint
MEDIA_CONVERT_JOB_QUEUE_ARN: !Ref MediaConvertJobQueueArn
MEDIA_CONVERT_ROLE_ARN: !Ref MediaConvertRoleArn
PYRAMID_BUCKET: !Ref PyramidBucket
REPOSITORY_EMAIL: !Ref RepositoryEmail
START_AUDIO_TRANSCODE_FUNCTION: !GetAtt startAudioTranscodeFunction.Arn
START_TRANSCODE_FUNCTION: !GetAtt startTranscodeFunction.Arn
TRANSCODE_STATUS_FUNCTION: !GetAtt transcodeStatusFunction.Arn
GET_DOWNLOAD_LINK_FUNCTION: !GetAtt getDownloadLinkFunction.Arn
SEND_TEMPLATED_EMAIL_FUNCTION: !GetAtt sendTemplatedEmailFunction.Arn
Policies:
- !Ref readSecretsPolicy
- Version: 2012-10-17
Statement:
- Sid: ExecuteAVDownloadStepFunction
Effect: Allow
Action:
- states:StartExecution
Resource:
- !Ref avDownloadStateMachine
- Sid: BucketAccess
Effect: Allow
Action:
- s3:GetObject
Resource: !Sub "arn:aws:s3:::${PyramidBucket}/*"
Events:
ApiGet:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /file-sets/{id}/download
Method: GET
ApiHead:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /file-sets/{id}/download
Method: HEAD
getWorkAuthFunction:
Type: AWS::Serverless::Function
Properties:
Handler: handlers/get-work-auth.handler
Description: Authorizes access to a work.
Layers:
- !Ref apiDependencies
Environment:
Variables:
USE_PROXIED_IP: true
Policies:
- !Ref readSecretsPolicy
- !Ref readIndexPolicy
Events:
ApiGet:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /works/{id}/authorization
Method: GET
ApiHead:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /works/{id}/authorization
Method: HEAD
getWorkByIdFunction:
Type: AWS::Serverless::Function
Properties:
Handler: handlers/get-work-by-id.handler
Description: Gets a Work by id.
Layers:
- !Ref apiDependencies
Environment:
Variables:
USE_PROXIED_IP: true
Policies:
- !Ref readSecretsPolicy
- !Ref readIndexPolicy
Events:
ApiGet:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /works/{id}
Method: GET
ApiHead:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /works/{id}
Method: HEAD
getThumbnailFunction:
Type: AWS::Serverless::Function
Properties:
Handler: handlers/get-thumbnail.handler
Description: Gets a Work's representative thumbnail.
Layers:
- !Ref apiDependencies
Policies:
- !Ref readSecretsPolicy
- !Ref readIndexPolicy
Events:
CollectionApiGet:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /collections/{id}/thumbnail
Method: GET
CollectionApiHead:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /collections/{id}/thumbnail
Method: HEAD
WorkApiGet:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /works/{id}/thumbnail
Method: GET
WorkApiHead:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /works/{id}/thumbnail
Method: HEAD
getSimilarFunction:
Type: AWS::Serverless::Function
Properties:
Handler: handlers/get-similar.handler
Timeout: 100
Description: Gets works similar to a specific work.
Layers:
- !Ref apiDependencies
Policies:
- !Ref readSecretsPolicy
- !Ref readIndexPolicy
Events:
WorkApiGet:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /works/{id}/similar
Method: GET
WorkApiHead:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /works/{id}/similar
Method: HEAD
searchPostFunction:
Type: AWS::Serverless::Function
Properties:
Handler: handlers/search.postSearch
Description: Handles OpenSearch search requests, Works only by default.
Layers:
- !Ref apiDependencies
Policies:
- !Ref readSecretsPolicy
- !Ref readIndexPolicy
Events:
SearchApi:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /search
Method: POST
SearchWithModelsApi:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /search/{models}
Method: POST
searchGetFunction:
Type: AWS::Serverless::Function
Properties:
Handler: handlers/search.getSearch
Description: Handles paging requests
Layers:
- !Ref apiDependencies
Policies:
- !Ref readSecretsPolicy
- !Ref readIndexPolicy
Events:
SearchApiGet:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /search
Method: GET
SearchApiHead:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /search
Method: HEAD
SearchWithModelsApiGet:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /search/{models}
Method: GET
SearchWithModelsApiHead:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /search/{models}
Method: HEAD
optionsFunction:
Type: AWS::Serverless::Function
Properties:
Handler: handlers/options-request.handler
Timeout: 3
Description: Handles all OPTIONS requests
Layers:
- !Ref apiDependencies
Policies:
- !Ref readSecretsPolicy
Events:
Everything:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /{proxy+}
Method: OPTIONS
getSharedLinkByIdFunction:
Type: AWS::Serverless::Function
Properties:
Handler: handlers/get-shared-link-by-id.handler
Description: Gets a shared link document by id.
Layers:
- !Ref apiDependencies
Policies:
- !Ref readSecretsPolicy
- !Ref readIndexPolicy
Events:
ApiGet:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /shared-links/{id}
Method: GET
ApiHead:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /shared-links/{id}
Method: HEAD
oaiFunction:
Type: AWS::Serverless::Function
Properties:
Handler: handlers/oai.handler
Description: Transforms works into OAI Records.
Layers:
- !Ref apiDependencies
Timeout: 60
Policies:
- !Ref readSecretsPolicy
- !Ref readIndexPolicy
Events:
GetApiGet:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /oai
Method: GET
GetApiHead:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /oai
Method: HEAD
PostApi:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /oai
Method: POST
chatWebsocket:
Type: AWS::Serverless::Application
Properties:
Location: ./chat/template.yaml
Parameters:
ApiTokenSecret: !Ref ApiTokenSecret
EnvironmentPrefix: !Ref EnvironmentPrefix
HoneybadgerApiKey: !Ref HoneybadgerApiKey
HoneybadgerEnv: !Ref HoneybadgerEnv
HoneybadgerRevision: !Ref HoneybadgerRevision
SecretsPath: !Ref SecretsPath
SecretsPolicy: !Ref readSecretsPolicy
chatWebsocketEndpoint:
Type: AWS::Serverless::Function
Properties:
Handler: handlers/get-chat-endpoint.handler
Description: Returns the URI of the chat websocket API.
Layers:
- !Ref apiDependencies
Environment:
Variables:
WEBSOCKET_URI: !GetAtt chatWebsocket.Outputs.WebSocketURI
Policies:
- !Ref readSecretsPolicy
Events:
GetApiGet:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /chat/endpoint
Method: GET
chatFeedback:
Type: AWS::Serverless::Function
Properties:
Handler: handlers/post-chat-feedback.handler
Description: Handles feedback from the chat.
Layers:
- !Ref apiDependencies
Environment:
Variables:
CHAT_FEEDBACK_BUCKET: !Ref chatFeedbackBucket
CHAT_FEEDBACK_TOPIC_ARN: !Ref chatFeedbackTopic
Policies:
- !Ref readSecretsPolicy
- Version: 2012-10-17
Statement:
- Sid: BucketAccess
Effect: Allow
Action:
- s3:PutObject
Resource: !Sub "arn:aws:s3:::${chatFeedbackBucket}/*"
- Sid: TopicAccess
Effect: Allow
Action:
- sns:Publish
Resource: !Ref chatFeedbackTopic
Events:
PostApi:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: /chat/feedback
Method: POST
chatFeedbackBucket:
Type: 'AWS::S3::Bucket'
Properties:
BucketName:
Fn::Join:
- "-"
- - !Sub "${AWS::StackName}-chat-feedback"
- !Select [2, !Split ['/', !Ref AWS::StackId]]
chatFeedbackTopic:
Type: AWS::SNS::Topic
Properties:
DisplayName: DC Chat Feedback
TopicName: !Sub "${AWS::StackName}-chat-feedback"
defaultFunction:
Type: AWS::Serverless::Function
Properties:
Handler: handlers/default-request.handler
Timeout: 3
Description: Handles all other requests
Layers:
- !Ref apiDependencies
Policies:
- !Ref readSecretsPolicy
Events:
Everything:
Type: HttpApi
Properties:
ApiId: !Ref dcApi
Path: $default
Method: ANY
# Resources for AV Download state machine
avDownloadStateMachine:
Type: AWS::Serverless::StateMachine
Properties:
DefinitionUri: ./state_machines/av_download.json
Name: !Sub "${AWS::StackName}-av-download-state-machine"
Policies:
- !Ref readSecretsPolicy
- Version: 2012-10-17
Statement:
- Sid: LambaInvokePermissions
Effect: Allow
Action:
- lambda:InvokeFunction
Resource:
- !GetAtt startAudioTranscodeFunction.Arn
- !GetAtt startTranscodeFunction.Arn
- !GetAtt transcodeStatusFunction.Arn
- !GetAtt getDownloadLinkFunction.Arn
- !GetAtt sendTemplatedEmailFunction.Arn
avDownloadEmailTemplate:
Type: AWS::SES::Template
Properties:
Template:
TemplateName: !Sub "${AWS::StackName}-av-download-template"
SubjectPart: Download of {{fileSetLabel}} is ready!
TextPart: |
Hello,
Your request for {{fileType}} download of {{fileSetLabel}} (file set id: {{fileSetId}}) has been fulfilled. Your download will be available for 3 days.
The {{fileType}} file can be downloaded from {{downloadLink}}
HtmlPart: |
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<title>NUL Meadow Download</title>
<meta content='IE=edge' http-equiv='X-UA-Compatible' />
<style>
p {
margin-top: 0;
line-height: 1.4em;
}
a {
color: #4e2a84;
}
@media only screen and (max-width: 599px) {
table[class='body-table'] {
width: 100%;
}
img {
max-width: 100%;
height: auto !important;
}
}
@media only screen and (max-width: 510px) {
table[class='inside-table'] {
width: 100%;
padding: 0 10px 0 10px !important;
}
table[class='quote-table'] {
width: 100%;
}
table[class='quote-image-table'] {
width: 100%;
}
}
</style>
</head>
<body
style='
background-color: #f1f0f0;
padding: 0;
margin: 0;
font-family: Arial, Helvetica Neue, Helvetica, sans-serif;
font-size: 17px;
color: #342f2e;
'
>
<!--[if gte mso 15]><table border='0' cellpadding='0' cellspacing='0' width='100%' align='left'><tr><td><![endif]-->
<table
align='center'
border='0'
cellpadding='0'
cellspacing='0'
class='body-table'
style='border: 1px solid #d8d6d6; background-color: #ffffff'
width='600'
>
<!-- header -->
<tbody>
<tr>
<td>
<table
border='0'
cellpadding='0'
cellspacing='0'
style='margin-bottom: 40px'
width='100%'
>
<tbody>
<tr>
<td
align='center'
height='110'
style='background-color: #4e2a84; padding: 0 10px 0 10px'
valign='middle'
>
<h1>
<img src="https://nul-public.s3.amazonaws.com/work-archiver/northwestern_logo.png" alt="Northwestern University Logo" />
</h1>
</td>
</tr>
<tr>
<td
align='center'
height='40'
style='
background-color: #401f68;
font-size: 13px;
color: #ffffff;
font-style: italic;
'
valign='middle'
></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>
<table
align='center'
border='0'
cellpadding='0'
cellspacing='0'
class='inside-table'
style='margin-bottom: 40px; padding: 0 66px 0 66px'
width='100%'
>
<tbody>
<tr>
<td style='padding-bottom: 5px'>
<h2
style='
margin: 12px 0;
font-size: 32px;
line-height: 1.2em;
'
>
Hello,
</h2>
<p>
Your request for {{fileType}} download of <b>{{fileSetLabel}}</b> (file set id: {{fileSetId}}) has been
fulfilled. Click below to download your file:
</p>
<p style='text-align: center'>
<a href='{{downloadLink}}'>
<!-- icon licensed under Creative Commons (Attribution 3.0 Unported): https://www.iconfinder.com/icons/285629/zip_file_icon -->
<img src="https://iiif.dc.library.northwestern.edu/iiif/2/00000000-0000-0000-0000-000000000002/square/100,100/0/default.jpg" alt="{{downloadLink}}" />
</a>
</p>
<p style='text-align: center; font-style: italic'>
(Your <a href='{{downloadLink}}'>download</a> will be available for 3 days)
</p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<!-- footer -->
<tr>
<td>
<table
align='center'
border='0'
cellpadding='0'
cellspacing='0'
style='background-color: #4e2a84; padding: 20px 0 20px 0'
width='100%'
>
<tbody>
<tr>
<td align='center' style='padding-bottom: 10px'>
<p>
<a href='https://www.library.northwestern.edu'
><img
alt='Northwestern University Library'
src='https://nul-public.s3.amazonaws.com/work-archiver/northwestern-university.png'
/></a>
</p>
</td>
</tr>
<tr>
<td align='center' style='padding-bottom: 20px'>
<p style='font-size: 12px; font-weight: bold; margin: 0'>
<a
href='https://meadow.library.northwestern.edu'
style='color: #ffffff'
>VISIT MEADOW NOW</a
>
</p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<!--[if gte mso 15]></td></tr></table><![endif]-->
</body>
</html>
startAudioTranscodeFunction:
Type: AWS::Serverless::Function
Properties:
Runtime: nodejs16.x
CodeUri: ./lambdas
Handler: start-audio-transcode.handler
Description: Performs audio transcode job with ffmpeg
Timeout: 900
MemorySize: 10240
Layers:
- !Ref FfmpegLayer
Policies:
- !Ref readSecretsPolicy
- Version: 2012-10-17
Statement:
- Sid: BucketAccess
Effect: Allow
Action:
- s3:PutObject
Resource: !Sub "arn:aws:s3:::${MediaConvertDestinationBucket}/*"
Environment:
Variables:
MEDIA_CONVERT_DESTINATION_BUCKET: !Ref MediaConvertDestinationBucket
startTranscodeFunction:
Type: AWS::Serverless::Function
Properties:
Runtime: nodejs20.x
CodeUri: ./lambdas
Handler: start-transcode.handler
Description: Creates MediaConvert Job to transcode HLS stream
Environment:
Variables:
MEDIA_CONVERT_ENDPOINT: !Ref MediaConvertEndpoint
MEDIA_CONVERT_JOB_QUEUE_ARN: !Ref MediaConvertJobQueueArn
MEDIA_CONVERT_ROLE_ARN: !Ref MediaConvertRoleArn
Policies:
- !Ref readSecretsPolicy
- Version: 2012-10-17
Statement:
- Sid: PassMediaConvertRole
Effect: Allow
Action:
- iam:PassRole
Resource:
- !Ref MediaConvertRoleArn
- Sid: StartTranscodeJob
Effect: Allow
Action:
- mediaconvert:CreateJob
Resource: "*"