-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserverless.yml
157 lines (146 loc) · 5.29 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
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
service: proxyfront
provider:
name: aws
runtime: nodejs8.10
stage: ${file(./config.${opt:stage}.yml):STAGE}
plugins:
- serverless-lambda-version
- serverless-prune-plugin
- "@vingle/serverless-tag-plugin"
custom:
prune:
automatic: true
number: 5
package:
artifact: dst.zip
functions:
originRequest:
handler: handlers/origin-request.handler
memorySize: 128
timeout: 15
role: LambdaEdgeRole
originResponse:
handler: handlers/origin-response.handler
memorySize: 128
timeout: 1
role: LambdaEdgeRole
resources:
Conditions:
CreateRoute53Records:
Fn::Equals:
- ${file(./config.${opt:stage}.yml):CREATE_ROUTE53_RECORDS}
- "true"
Resources:
S3Bucket:
Type: AWS::S3::Bucket
Properties:
BucketName: ${file(./config.${opt:stage}.yml):BUCKET_NAME}
CloudfrontDistribution:
DependsOn: S3Bucket
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Aliases: ${file(./config.${opt:stage}.yml):CLOUDFRONT_CUSTOM_DOMAIN_NAMES}
Origins:
# This is dummy domain name. ProxyFront never sends actual requests to this domain!
- DomainName: aws.amazon.com
Id: DummyOrigin
CustomOriginConfig:
OriginProtocolPolicy: http-only
Enabled: true
Comment: proxyfront-${opt:stage}
IPV6Enabled: true
DefaultCacheBehavior:
AllowedMethods: ${file(./config.${opt:stage}.yml):CLOUDFRONT_ALLOWED_METHODS}
TargetOriginId: DummyOrigin
DefaultTTL: ${file(./config.${opt:stage}.yml):CLOUDFRONT_DEFAULT_TTL}
MinTTL: ${file(./config.${opt:stage}.yml):CLOUDFRONT_MIN_TTL}
MaxTTL: ${file(./config.${opt:stage}.yml):CLOUDFRONT_MAX_TTL}
ForwardedValues:
QueryString: true
Cookies:
Forward: ${file(./config.${opt:stage}.yml):CLOUDFRONT_FORWARD_COOKIE}
Headers: ${file(./config.${opt:stage}.yml):CLOUDFRONT_FORWARD_HEADER}
ViewerProtocolPolicy: redirect-to-https
LambdaFunctionAssociations:
- EventType: origin-request
LambdaFunctionARN: OriginRequestLambdaFunction
- EventType: origin-response
LambdaFunctionARN: OriginResponseLambdaFunction
CustomErrorResponses:
- ErrorCode: 400
ErrorCachingMinTTL: 0
- ErrorCode: 403
ErrorCachingMinTTL: 0
- ErrorCode: 404
ErrorCachingMinTTL: 0
- ErrorCode: 405
ErrorCachingMinTTL: 0
- ErrorCode: 414
ErrorCachingMinTTL: 0
- ErrorCode: 500
ErrorCachingMinTTL: 0
- ErrorCode: 501
ErrorCachingMinTTL: 0
- ErrorCode: 502
ErrorCachingMinTTL: 0
- ErrorCode: 503
ErrorCachingMinTTL: 0
- ErrorCode: 504
ErrorCachingMinTTL: 0
HttpVersion: http2
PriceClass: PriceClass_All
ViewerCertificate: ${file(./config.${opt:stage}.yml):CLOUDFRONT_VIEWER_CERTIFICATE}
Logging:
Bucket:
Fn::GetAtt:
- S3Bucket
- DomainName
Prefix: logs/cloudfront/raw/
CloudfrontRoute53Record:
Condition: CreateRoute53Records
Type: AWS::Route53::RecordSet
Properties:
Comment: proxyfront Cloudfront ${opt:stage} A (IPv4) Record
HostedZoneId: ${file(./config.${opt:stage}.yml):ROUTE53_HOSTED_ZONE_ID}
Name: ${file(./config.${opt:stage}.yml):ROUTE53_DOMAIN_NAME}
Type: A
AliasTarget:
# @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-route53-aliastarget.html#cfn-route53-aliastarget-hostedzoneid
HostedZoneId: Z2FDTNDATAQYW2 # This value is AWS-defined constant value.
DNSName:
Fn::Join:
- "."
- - Fn::GetAtt: [CloudfrontDistribution, DomainName]
- ""
CloudfrontRoute53IPv6Record:
Condition: CreateRoute53Records
Type: AWS::Route53::RecordSet
Properties:
Comment: proxyfront Cloudfront ${opt:stage} AAAA (IPv6) Record
HostedZoneId: ${file(./config.${opt:stage}.yml):ROUTE53_HOSTED_ZONE_ID}
Name: ${file(./config.${opt:stage}.yml):ROUTE53_DOMAIN_NAME}
Type: AAAA
AliasTarget:
# @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-route53-aliastarget.html#cfn-route53-aliastarget-hostedzoneid
HostedZoneId: Z2FDTNDATAQYW2 # This value is AWS-defined constant value.
DNSName:
Fn::Join:
- "."
- - Fn::GetAtt: [CloudfrontDistribution, DomainName]
- ""
LambdaEdgeRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- edgelambda.amazonaws.com
- lambda.amazonaws.com
Action:
- sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole