-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserverless.yml
More file actions
164 lines (154 loc) · 5.04 KB
/
serverless.yml
File metadata and controls
164 lines (154 loc) · 5.04 KB
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
service: quantum-mirror-lambda
provider:
name: aws
stage: ${opt:stage, 'prod'}
region: us-east-1
runtime: nodejs20.x
logRetentionInDays: 30
endpointType: regional
custom:
handlerDir:
prod: src
dummy: dummy
handlerJS:
prod: src/index
dummy: dummy/index
resources:
Resources:
# Dummy bucket for requests for unsupported paths to go to
CatchAllBucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: Private
CFOriginPolicyXAuthorization:
Type: AWS::CloudFront::OriginRequestPolicy
Properties:
OriginRequestPolicyConfig:
Name: ${self:service}-${self:provider.stage}-XAuthorization
CookiesConfig:
CookieBehavior: none
HeadersConfig:
HeaderBehavior: whitelist
Headers:
- X-Authorization # For the OpenAI bearer token
QueryStringsConfig:
QueryStringBehavior: all
CFImageCachePolicy:
Type: AWS::CloudFront::CachePolicy
Properties:
CachePolicyConfig:
Name: ${self:service}-${self:provider.stage}-ImageCache
DefaultTTL: 3600
MinTTL: 3600
MaxTTL: 86400
ParametersInCacheKeyAndForwardedToOrigin:
EnableAcceptEncodingBrotli: false
EnableAcceptEncodingGzip: false
CookiesConfig:
CookieBehavior: none
HeadersConfig:
HeaderBehavior: none
QueryStringsConfig:
QueryStringBehavior: all
CloudFrontDistribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
DefaultCacheBehavior:
TargetOriginId: s3-catch-all
Compress: false
CachePolicyId: 4135ea2d-6df8-44a3-9df3-4b5a84be39ad # CachingDisabled (AWS managed)
ViewerProtocolPolicy: https-only
CacheBehaviors:
# We don't pass any headers to this one (no X-Authorization)
- PathPattern: 'getImage/*'
TargetOriginId: get-image-function
Compress: false
CachePolicyId:
Ref: CFImageCachePolicy
ViewerProtocolPolicy: https-only
AllowedMethods:
- GET
- HEAD
- PathPattern: 'submitImage'
TargetOriginId: submit-image-function
Compress: false
CachePolicyId: 4135ea2d-6df8-44a3-9df3-4b5a84be39ad # CachingDisabled (AWS managed)
OriginRequestPolicyId:
Ref: CFOriginPolicyXAuthorization # Pass X-Authorization header to Lambda
ViewerProtocolPolicy: https-only
AllowedMethods:
- HEAD
- DELETE
- POST
- GET
- OPTIONS
- PUT
- PATCH
Enabled: true
Origins:
- Id: s3-catch-all
DomainName: !GetAtt CatchAllBucket.DomainName
S3OriginConfig: {}
- Id: get-image-function
DomainName: !Select [2, !Split ["/", !GetAtt GetImageLambdaFunctionUrl.FunctionUrl]]
CustomOriginConfig:
HTTPSPort: 443
OriginProtocolPolicy: https-only
OriginSSLProtocols:
- TLSv1.2
OriginReadTimeout: 30
- Id: submit-image-function
DomainName: !Select [ 2, !Split [ "/", !GetAtt SubmitImageLambdaFunctionUrl.FunctionUrl ] ]
CustomOriginConfig:
HTTPSPort: 443
OriginProtocolPolicy: https-only
OriginSSLProtocols:
- TLSv1.2
OriginReadTimeout: 60
ViewerCertificate:
CloudFrontDefaultCertificate: true
Outputs:
EndpointForCameraTokenTxt:
Value:
Fn::Join:
- ''
- - "https://"
- Fn::GetAtt:
- CloudFrontDistribution
- DomainName
- "/"
functions:
submitImage:
handler: ${self:custom.handlerJS.${self:provider.stage}}.submitImage
memorySize: 128
timeout: 120
layers:
- !Ref ImagemagickLambdaLayer
# Use function URLs so that we can avoid API Gateway 30 second timeout limit
url: true
getImage:
handler: ${self:custom.handlerJS.${self:provider.stage}}.getImage
memorySize: 1024
timeout: 30
layers:
- !Ref ImagemagickLambdaLayer
url: true
package:
patterns:
- '!*' # Exclude loose files in root if not included (e.g. config files)
- '!dummy/**' # Only for dummy stage
- '!imagemagick/**' # We pack these into a zip instead
- '!.idea/**'
- 'package*.json'
- ${self:custom.handlerDir.${self:provider.stage}}/**
layers:
# Built using https://github.com/serverlesspub/imagemagick-aws-lambda-2
#
# Then: cd imagemagick && zip --symlinks -r ../imagemagick.zip *
# Since otherwise serverless duplicates symlinks and zip is too big
imagemagick:
package:
artifact: imagemagick.zip
compatibleArchitectures:
- x86_64