-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserverless.yml
93 lines (87 loc) · 3.01 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
# Welcome to Serverless!
#
# This file is the main config file for your service.
# It's very minimal at this point and uses default values.
# You can always add more config options for more control.
# We've included some commented out config examples here.
# Just uncomment any of them to get that config option.
#
# For full config options, check the docs:
# docs.serverless.com
#
# Happy Coding!
service: iris
provider:
name: aws
runtime: nodejs6.10
memorySize: 1536
environment:
API_GATEWAY: { "Fn::Join": ["", [{ "Ref": "ApiGatewayRestApi" }, ".execute-api.${self:provider.region}.amazonaws.com"]]}
BUCKET: { "Ref": "MediaServer" }
BUCKET_DOMAIN: { "Fn::Join": ["", [{ "Ref": "MediaServer" }, ".s3-website-${self:provider.region}.amazonaws.com"]]}
CLOUDFRONT_URL: { "Fn::Join": ["", ["https://", { "Fn::GetAtt": ["MediaCDN", "DomainName"] }]]}
ERROR_DOCUMENT: 404.html
#CERT_DOMAIN: *.example.com
#CERT_VALIDATION_DOMAIN: example.com
#CERT_ARN: { "Ref": "CDNCert" }
iamRoleStatements:
- Effect: "Allow"
Action:
- "s3:*"
Resource: "*"
package:
artifact: dist/iris.zip
functions:
resizeImage:
handler: handler.resizeImage
events:
- http: GET resizeImage
resources:
Resources:
#CDNCert:
# Type: AWS::CertificateManager::Certificate
# Properties:
# DomainName: ${self:provider.environment.CERT_DOMAIN}
# DomainValidationOptions:
# - DomainName: ${self:provider.environment.CERT_DOMAIN}
# ValidationDomain: ${self:provider.environment.CERT_VALIDATION_DOMAIN}
MediaServer:
Type: AWS::S3::Bucket
DeletionPolicy: Retain
Properties:
AccessControl: PublicRead
WebsiteConfiguration:
IndexDocument: index.html
ErrorDocument: ${self:provider.environment.ERROR_DOCUMENT}
RoutingRules:
- RedirectRule:
HttpRedirectCode: 307
Protocol: https
HostName: ${self:provider.environment.API_GATEWAY}
ReplaceKeyPrefixWith: ${self:provider.stage}/resizeImage?key=
RoutingRuleCondition:
HttpErrorCodeReturnedEquals: 404
MediaCDN:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Origins:
- DomainName: ${self:provider.environment.BUCKET_DOMAIN}
Id: MediaServerS3Origin
CustomOriginConfig:
HTTPPort: '80'
HTTPSPort: '443'
OriginProtocolPolicy: http-only
Enabled: 'true'
DefaultCacheBehavior:
Compress: 'true'
DefaultTTL: 0
ForwardedValues:
QueryString: 'false'
TargetOriginId: MediaServerS3Origin
ViewerProtocolPolicy: redirect-to-https
#Aliases:
# - ${self:provider.environment.CERT_DOMAIN}
#ViewerCertificate:
# AcmCertificateArn: ${self:provider.environment.CERT_ARN}
# SslSupportMethod: sni-only