-
Notifications
You must be signed in to change notification settings - Fork 34
/
serverless.yml
123 lines (120 loc) · 3.8 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
service: ${self:custom.settings.serviceName}
provider:
name: aws
runtime: nodejs14.x
timeout: 10
stage: ${opt:stage,'dev'}
region: ${self:custom.settings.region}
iam:
role:
statements:
- Effect: "Allow"
Action:
- "s3:GetObject"
Resource: "arn:aws:s3:::${self:custom.settings.environment.SOURCE_BUCKET}/*"
apiGateway:
binaryMediaTypes:
- '*/*'
layers:
sharp:
path: lambdaLayers/SharpLayer # required, path to layer contents on disk
name: ${self:provider.stage}-sharp # optional, Deployed Lambda layer name
package:
include:
- node_modules/**
description: [email protected]
compatibleRuntimes:
- nodejs14.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
Origins:
- Id: ApiGateway
DomainName:
Fn::Join:
- "."
- - Ref: ApiGatewayRestApi
- execute-api.${self:custom.settings.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:
package:
individually: true
exclude:
- 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: ${self:custom.settings.offlinePort}
noPrependStageInUrl: true
plugins:
- serverless-offline