forked from venveo/serverless-sharp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserverless.yml
132 lines (129 loc) · 3.95 KB
/
serverless.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
org: proclame
app: image-handler-imgix-alt
service: image-handler-imgix-alt
provider:
name: aws
runtime: nodejs16.x
timeout: 28
stage: ${opt:stage,'dev'}
region: 'eu-central-1'
logs:
restApi: false
iam:
role:
statements:
- Effect: "Allow"
Action:
- "s3:GetObject"
- "s3:PutObject"
Resource: "arn:aws:s3:::${self:custom.settings.environment.SOURCE_BUCKET}/*"
apiGateway:
shouldStartNameWithService: true
binaryMediaTypes:
- '*/*'
layers:
sharp:
path: lambdaLayers/SharpLayer # required, path to layer contents on disk
name: ${self:provider.stage}-sharp # optional, Deployed Lambda layer name
package:
patterns:
- node_modules/**
description: [email protected]
compatibleRuntimes:
- nodejs16.x
- nodejs18.x
licenseInfo: Apache License 2.0
retain: false
resources:
Conditions:
CustomDomain: !Not [!Equals ["${self:custom.settings.environment.CUSTOM_DOMAIN, ''}", ""]]
ArnCertificate: !Not [!Equals ["${self:custom.settings.environment.ACM_CERTIFICATE_ARN, ''}", ""]]
CreateCertificate: !And
- !Not [!Equals ["${self:custom.settings.environment.CUSTOM_DOMAIN, ''}", ""]]
- !Equals ["${self:custom.settings.environment.ACM_CERTIFICATE_ARN, ''}", ""]
Resources:
CloudFrontDistribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Comment: Cloudfront distribution for serverless image handler
DefaultCacheBehavior:
TargetOriginId: ApiGateway
ViewerProtocolPolicy: 'redirect-to-https'
DefaultTTL: 30
ForwardedValues:
Headers:
- 'Accept'
QueryString: true
Enabled: true
HttpVersion: 'http2'
Origins:
- Id: ApiGateway
DomainName:
Fn::Join:
- "."
- - Ref: ApiGatewayRestApi
- execute-api.${self:provider.region}.amazonaws.com
OriginPath: "/${self:provider.stage}"
CustomOriginConfig:
HTTPPort: 80
HTTPSPort: 443
OriginProtocolPolicy: https-only
Aliases:
Fn::If:
- CustomDomain
- - '${self:custom.settings.environment.CUSTOM_DOMAIN, ""}'
- Ref: AWS::NoValue
ViewerCertificate:
Fn::If:
- ArnCertificate
- MinimumProtocolVersion: 'TLSv1'
SslSupportMethod: 'sni-only'
AcmCertificateArn: ${self:custom.settings.environment.ACM_CERTIFICATE_ARN,''}
- Fn::If:
- CreateCertificate
- MinimumProtocolVersion: 'TLSv1'
SslSupportMethod: 'sni-only'
AcmCertificateArn:
Ref: Certificate
- Ref: AWS::NoValue
Certificate:
Type: AWS::CertificateManager::Certificate
Condition: CreateCertificate
Properties:
ValidationMethod: DNS
DomainName: '${self:custom.settings.environment.CUSTOM_DOMAIN}'
Outputs:
CloudFrontDistributionOutput:
Value:
'Fn::GetAtt': [ CloudFrontDistribution, DomainName ]
functions:
index:
memorySize: 5120
package:
individually: true
patterns:
- '!node_modules/**'
- '!docs/**'
- '!.idea/**'
- '!bin/darwin/**'
- '!coverage/**'
handler: src/index.handler
layers:
- { Ref: SharpLambdaLayer }
events:
- http:
path: /{any+}
method: get
response:
contentHandling: CONVERT_TO_BINARY
environment: ${self:custom.settings.environment}
custom:
empty: ''
settingsFilePath: ${opt:settings,'./settings.yml'}
settings: ${file(${self:custom.settingsFilePath}):stages.${self:provider.stage}}
serverless-offline:
httpPort: 3003
noPrependStageInUrl: true
plugins:
- serverless-offline