-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverless.yml
97 lines (90 loc) · 2.62 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
service: learning-caching-headers
frameworkVersion: '3'
provider:
name: aws
stage: prod
runtime: nodejs12.x
region: "us-east-1"
logRetentionInDays: 14
plugins:
- serverless-plugin-typescript
package:
patterns:
- '!*/**'
- handler.js
resources:
Description: "CloudFormation template for ${self:service}"
Resources:
CloudFrontFunction:
Type: AWS::CloudFront::Function
Properties:
Name: DateHeaderSet
AutoPublish: true
FunctionCode: !Sub |
function handler(event) {
var response = event.response;
response.headers['date'] = {
// https://stackoverflow.com/a/18324177/3141881
value: new Date().toUTCString()
};
delete response.headers['age'];
return response;
}
FunctionConfig:
Comment: !Sub Update the date header
Runtime: cloudfront-js-1.0
CloudFrontDistribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Origins:
- Id: ApiGateway
DomainName:
Fn::Join:
- "."
- - Ref: HttpApi
- execute-api
- Ref: AWS::Region
- Ref: AWS::URLSuffix
CustomOriginConfig:
HTTPPort: '80'
HTTPSPort: '443'
OriginProtocolPolicy: https-only
OriginSSLProtocols: [ "TLSv1", "TLSv1.1", "TLSv1.2" ]
Enabled: 'true'
HttpVersion: http2
IPV6Enabled: true
DefaultCacheBehavior:
Compress: 'true'
ForwardedValues:
QueryString: 'false'
Cookies:
Forward: none
AllowedMethods:
- GET
- HEAD
- OPTIONS
TargetOriginId: ApiGateway
ViewerProtocolPolicy: redirect-to-https
FunctionAssociations:
- EventType: viewer-response
FunctionARN: !GetAtt CloudFrontFunction.FunctionMetadata.FunctionARN
PriceClass: PriceClass_100
CustomErrorResponses:
- ErrorCode: 403
ResponseCode: 404
ResponsePagePath: "/404.html"
ViewerCertificate:
CloudFrontDefaultCertificate: true
Outputs:
ApiDistribution:
Value:
Fn::GetAtt: [ CloudFrontDistribution, DomainName ]
functions:
hello:
handler: handler.handleRequest
memorySize: 128
events:
- httpApi:
path: /
method: GET