forked from samvera/serverless-iiif
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yml
324 lines (324 loc) · 10.4 KB
/
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
Transform: "AWS::Serverless-2016-10-31"
Metadata:
AWS::ServerlessRepo::Application:
Name: serverless-iiif-cloudfront
Description: IIIF Image API 2.1 server in an AWS Serverless Application (w/CloudFront Caching)
Author: Samvera
SpdxLicenseId: Apache-2.0
LicenseUrl: ../../LICENSE.txt
ReadmeUrl: ../../README.md
Labels: ["iiif", "image-processing"]
HomePageUrl: https://github.com/samvera-labs/serverless-iiif
SemanticVersion: 4.0.3
SourceCodeUrl: https://github.com/samvera-labs/serverless-iiif
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: "General Configuration"
Parameters:
- SourceBucket
- IiifLambdaMemory
- IiifLambdaTimeout
- PixelDensity
- ResolverTemplate
- Label:
default: "Cache Configuration"
Parameters:
- CachePolicyID
- CachePriceClass
- Label:
default: "Hostname Configuration"
Parameters:
- CacheDomainName
- CacheSSLCertificate
- Label:
default: "Function Configuration"
Parameters:
- OriginRequestARN
- OriginResponseARN
- ViewerRequestARN
- ViewerRequestType
- ViewerResponseARN
- ViewerResponseType
Parameters:
CachePolicyID:
Type: String
Description: The ID of a managed or custom CloudFront Cache Policy to use
Default: 658327ea-f89d-4fab-a63d-7e88639e58f6
CachePriceClass:
Type: String
Description: Price Class for the CloudFront Cache
Default: PriceClass_100
AllowedValues:
- PriceClass_100
- PriceClass_200
- PriceClass_All
CacheDomainName:
Type: String
Description: Custom Domain Name for the API Gateway Endpoint or CloudFront Cache
Default: ""
CacheSSLCertificate:
Type: String
Description: ARN of the ACM SSL Certification to use for the API Gateway Endpoint or CloudFront Cache
Default: ""
SourceBucket:
Type: String
Description: Name of bucket containing source images
IiifLambdaMemory:
Type: Number
Description: The memory provisioned for the lambda.
MinValue: 128
MaxValue: 10240
Default: 3008
IiifLambdaTimeout:
Type: Number
Description: The timeout for the lambda.
Default: 10
OriginRequestARN:
Type: String
Description: ARN of the Lambda@Edge Function to use at the origin-request stage
Default: ""
OriginResponseARN:
Type: String
Description: ARN of the Lambda@Edge Function to use at the origin-response stage
Default: ""
PixelDensity:
Type: Number
Description: Hardcoded DPI/Pixel Density/Resolution to encode in output images
Default: 0
MinValue: 0
ResolverTemplate:
Type: String
Description: A printf-style format string that determines the location of source image within the bucket given the image ID
Default: "%s.tif"
ViewerRequestARN:
Type: String
Description: ARN of the CloudFront or Lambda@Edge Function to use at the viewer-request stage
Default: ""
ViewerRequestType:
Type: String
Description: Type of viewer-request Function to use (CloudWatch Function or Lambda@Edge)
Default: "None"
AllowedValues:
- CloudWatch Function
- Lambda@Edge
- None
ViewerResponseARN:
Type: String
Description: ARN of the CloudFront or Lambda@Edge Function to use at the viewer-response stage
Default: ""
ViewerResponseType:
Type: String
Description: Type of viewer-response Function to use (CloudWatch Function or Lambda@Edge)
Default: "None"
AllowedValues:
- CloudWatch Function
- Lambda@Edge
- None
Conditions:
DistributionCustomDomain:
Fn::And:
- Fn::Not:
- Fn::Equals: [!Ref CacheDomainName, ""]
- Fn::Not:
- Fn::Equals: [!Ref CacheSSLCertificate, ""]
UseOriginRequest:
Fn::Not:
- Fn::Equals: [!Ref OriginRequestARN, ""]
UseOriginResponse:
Fn::Not:
- Fn::Equals: [!Ref OriginResponseARN, ""]
UseViewerRequest:
Fn::And:
- Fn::Not:
- Fn::Equals: [!Ref ViewerRequestType, "None"]
- Fn::Not:
- Fn::Equals: [!Ref ViewerRequestARN, ""]
UseViewerResponse:
Fn::And:
- Fn::Not:
- Fn::Equals: [!Ref ViewerResponseType, "None"]
- Fn::Not:
- Fn::Equals: [!Ref ViewerResponseARN, ""]
ViewerRequestCloudWatchFunction:
Fn::And:
- Condition: UseViewerRequest
- Fn::Equals: [!Ref ViewerRequestType, "CloudWatch Function"]
ViewerRequestLambda:
Fn::And:
- Condition: UseViewerRequest
- Fn::Equals: [!Ref ViewerRequestType, "Lambda@Edge"]
ViewerResponseCloudWatchFunction:
Fn::And:
- Condition: UseViewerResponse
- Fn::Equals: [!Ref ViewerResponseType, "CloudWatch Function"]
ViewerResponseLambda:
Fn::And:
- Condition: UseViewerResponse
- Fn::Equals: [!Ref ViewerResponseType, "Lambda@Edge"]
Resources:
CacheBucket:
Type: "AWS::S3::Bucket"
Properties:
BucketName:
Fn::Sub: "${AWS::StackName}-cache"
LifecycleConfiguration:
Rules:
- Status: Enabled
ExpirationInDays: 1
PublicAccessBlockConfiguration:
BlockPublicAcls : true
BlockPublicPolicy : true
IgnorePublicAcls : true
RestrictPublicBuckets : true
CacheBucketPolicy:
Type: "AWS::S3::BucketPolicy"
Properties:
Bucket: !Ref CacheBucket
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- s3:GetObject
Resource:
- Fn::Sub: "arn:aws:s3:::${CacheBucket}/*"
Principal:
CanonicalUser:
Fn::GetAtt: CachingIdentity.S3CanonicalUserId
CachingIdentity:
Type: "AWS::CloudFront::CloudFrontOriginAccessIdentity"
Properties:
CloudFrontOriginAccessIdentityConfig:
Comment: "Caching Distribution Identity"
CachingEndpoint:
Type: "AWS::CloudFront::Distribution"
Properties:
DistributionConfig:
Enabled: true
PriceClass: !Ref CachePriceClass
Aliases:
Fn::If:
- DistributionCustomDomain
- - !Ref CacheDomainName
- !Ref AWS::NoValue
ViewerCertificate:
Fn::If:
- DistributionCustomDomain
- AcmCertificateArn: !Ref CacheSSLCertificate
MinimumProtocolVersion: 'TLSv1'
SslSupportMethod: 'sni-only'
- CloudFrontDefaultCertificate: true
Origins:
- Id: IiifLambda
CustomOriginConfig:
OriginProtocolPolicy: https-only
DomainName:
Fn::GetAtt: IiifFunction.Outputs.FunctionDomain
- Id: IiifCache
S3OriginConfig:
OriginAccessIdentity:
Fn::Join:
- ''
- - 'origin-access-identity/cloudfront/'
- !Ref CachingIdentity
DomainName:
Fn::Sub: "${CacheBucket}.s3.${AWS::Region}.amazonaws.com"
OriginGroups:
Quantity: 1
Items:
- Id: IiifOrigins
Members:
Quantity: 2
Items:
- OriginId: IiifLambda
- OriginId: IiifCache
FailoverCriteria:
StatusCodes:
Items: [404]
Quantity: 1
DefaultCacheBehavior:
TargetOriginId: IiifOrigins
ViewerProtocolPolicy: https-only
AllowedMethods: ["GET", "HEAD", "OPTIONS"]
CachedMethods: ["GET", "HEAD"]
CachePolicyId: !Ref CachePolicyID
FunctionAssociations:
- Fn::If:
- ViewerRequestCloudWatchFunction
- EventType: viewer-request
FunctionARN: !Ref ViewerRequestARN
- !Ref AWS::NoValue
- Fn::If:
- ViewerResponseCloudWatchFunction
- EventType: viewer-response
FunctionARN: !Ref ViewerResponseARN
- !Ref AWS::NoValue
LambdaFunctionAssociations:
- Fn::If:
- ViewerRequestLambda
- EventType: viewer-request
LambdaFunctionARN: !Ref ViewerRequestARN
IncludeBody: false
- !Ref AWS::NoValue
- Fn::If:
- UseOriginRequest
- EventType: origin-request
LambdaFunctionARN: !Ref OriginRequestARN
IncludeBody: false
- !Ref AWS::NoValue
- Fn::If:
- UseOriginResponse
- EventType: origin-response
LambdaFunctionARN: !Ref OriginResponseARN
IncludeBody: false
- !Ref AWS::NoValue
- Fn::If:
- ViewerResponseLambda
- EventType: viewer-response
LambdaFunctionARN: !Ref ViewerResponseARN
IncludeBody: false
- !Ref AWS::NoValue
IiifFunction:
Type: AWS::Serverless::Application
Properties:
# Swap the comment characters on the two Location properties and update SemanticVersion
# when publishing to SAR
Location: ../standalone/template.yml
# Location:
# ApplicationId: arn:aws:serverlessrepo:us-east-1:625046682746:applications/serverless-iiif-standalone
# SemanticVersion: 4.0.3
Parameters:
CacheBucket: !Ref CacheBucket
ForceHost:
Fn::If:
- DistributionCustomDomain
- !Ref CacheDomainName
- !Ref AWS::NoValue
IiifLambdaMemory: !Ref IiifLambdaMemory
IiifLambdaTimeout: !Ref IiifLambdaTimeout
PixelDensity: !Ref PixelDensity
Preflight:
Fn::If:
- UseViewerRequest
- true
- false
ResolverTemplate: !Ref ResolverTemplate
SourceBucket: !Ref SourceBucket
Outputs:
Endpoint:
Description: IIIF Endpoint URL
Value:
Fn::If:
- DistributionCustomDomain
- Fn::Sub: "https://${CacheDomainName}/iiif/2/"
- Fn::Sub: "https://${CachingEndpoint.DomainName}/iiif/2/"
DistributionId:
Description: Caching Distribution ID
Value:
Ref: CachingEndpoint
Export:
Name: !Sub "${AWS::StackName}:DistributionId"
LambdaFunction:
Description: IIIF Lambda Function Name
Value: !Ref IiifFunction