-
Notifications
You must be signed in to change notification settings - Fork 0
/
serverless.yml
138 lines (133 loc) · 4.47 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
service: covid19-dashboard
frameworkVersion: '3'
provider:
name: aws
region: ${opt:region, self:custom.region}
runtime: nodejs12.x
stackName: ${self:service}-stack
stackTags: # Optional CF stack tags
project: ${self:custom.project}
custom:
region: ap-southeast-1
project: covid-19
rootDomain: drunkard-pig.com
siteName: dashboard.covid-19.${self:custom.rootDomain}
certArn: ${opt:certArn, ''}
s3BucketLogBucket: ${self:custom.client.bucketName}-logs
client:
bucketName: ${self:custom.siteName}
distributionFolder: build
indexDocument: index.html
objectHeaders:
'*.html':
- name: Cache-Control
value: no-cache
remover:
buckets:
- ${self:custom.client.bucketName}
- ${self:custom.s3BucketLogBucket}
resources:
Resources:
Covid19DashboardLogBucket:
Type: AWS::S3::Bucket
DeletionPolicy: Delete
Properties:
AccessControl: LogDeliveryWrite
BucketName: ${self:custom.s3BucketLogBucket}
LifecycleConfiguration:
Rules:
- Id: ExpireRule
Status: Enabled
ExpirationInDays: 30
Covid19DashboardBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: ${self:custom.client.bucketName}
AccessControl: PublicRead
WebsiteConfiguration:
IndexDocument: index.html
ErrorDocument: index.html
LoggingConfiguration:
DestinationBucketName:
Ref: Covid19DashboardLogBucket
LogFilePrefix: bucket-log/
# specifying the policies to make sure all files inside the Bucket are available
Covid19DashboardBucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket:
Ref: Covid19DashboardBucket
PolicyDocument:
Statement:
- Sid: PublicReadGetObject
Effect: Allow
Principal: "*"
Action:
- s3:GetObject
Resource: arn:aws:s3:::${self:custom.client.bucketName}/*
## Specifying the CloudFront Distribution to server your Web Application
Covid19DashboardCloudFrontDistribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Origins:
- DomainName: ${self:custom.client.bucketName}.s3-website.${self:provider.region}.amazonaws.com
Id: Covid19DashboardCloudFrontDistributionOrigin
CustomOriginConfig:
HTTPPort: 80
HTTPSPort: 443
OriginProtocolPolicy: http-only
OriginSSLProtocols:
- TLSv1
- TLSv1.1
- TLSv1.2
HttpVersion: http2
Enabled: true
Aliases:
- ${self:custom.client.bucketName}
DefaultCacheBehavior:
AllowedMethods:
- DELETE
- GET
- HEAD
- OPTIONS
- PATCH
- POST
- PUT
TargetOriginId: Covid19DashboardCloudFrontDistributionOrigin
ForwardedValues:
QueryString: false
Cookies:
Forward: none
ViewerProtocolPolicy: redirect-to-https
Compress: true
CachePolicyId:
# Managed-CachingOptimized
658327ea-f89d-4fab-a63d-7e88639e58f6
OriginRequestPolicyId:
# Managed-CORS-S3Origin
88a5eaf4-2fd4-4709-b370-b4c650ea3fcf
ViewerCertificate:
AcmCertificateArn: ${self:custom.certArn}
SslSupportMethod: sni-only
MinimumProtocolVersion: TLSv1.2_2019
# https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/AccessLogs.html#access-logs-choosing-s3-bucket
Logging:
Bucket: { "Fn::GetAtt": [ "Covid19DashboardLogBucket", "DomainName" ] }
IncludeCookies: false
Prefix: cloud-front-log/
# add A record to link the custom domain to CloudFront
Covid19DashboardRoute53RecordSet:
Type: AWS::Route53::RecordSetGroup
Properties:
HostedZoneName: "${self:custom.rootDomain}."
RecordSets:
- Name: ${self:custom.siteName}
Type: A
AliasTarget:
# it must be Z2FDTNDATAQYW2
HostedZoneId: Z2FDTNDATAQYW2
DNSName: { "Fn::GetAtt": [ "Covid19DashboardCloudFrontDistribution", "DomainName" ] }
plugins:
- serverless-finch
- serverless-s3-remover