/
ClientDistribution.ts
65 lines (64 loc) · 2.14 KB
/
ClientDistribution.ts
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
import { CloudFront, Fn } from "cloudform";
import { config } from "../../config";
import { pascalCaseDomainName } from "../../lib";
export const ClientDistribution = new CloudFront.Distribution({
DistributionConfig: {
Aliases: [Fn.Join(".", [Fn.Ref("SubDomain"), config.ROOT_DOMAIN])],
Comment: Fn.Join("", [
"cloudfront distribution for ",
Fn.Ref("SubDomain"),
".",
config.ROOT_DOMAIN
]),
CustomErrorResponses: [
{
ErrorCachingMinTTL: 60,
ErrorCode: 404,
ResponseCode: 404,
ResponsePagePath: "/index.html"
}
],
DefaultCacheBehavior: {
AllowedMethods: ["GET", "HEAD"],
TargetOriginId: "s3Origin",
Compress: true,
DefaultTTL: 1,
MinTTL: 1,
ViewerProtocolPolicy: "redirect-to-https",
ForwardedValues: {
QueryString: false,
Cookies: {
Forward: "none"
}
}
},
DefaultRootObject: "index.html",
Enabled: true,
HttpVersion: "http2",
// Logging: {
// IncludeCookies: false,
// Bucket: '', // TODO:
// Prefix: '' // TODO:
// },
Origins: [
{
Id: "s3Origin",
DomainName: Fn.GetAtt("ClientBucket", "DomainName"),
S3OriginConfig: {
OriginAccessIdentity: Fn.Join("/", [
"origin-access-identity/cloudfront",
Fn.Ref("ClientOriginAccessIdentity")
])
}
}
],
PriceClass: "PriceClass_100", // PriceClass_100 | PriceClass_200 | PriceClass_All
ViewerCertificate: {
AcmCertificateArn: Fn.ImportValue(
`${pascalCaseDomainName(config.ROOT_DOMAIN)}Certificate`
),
MinimumProtocolVersion: "TLSv1.1_2016",
SslSupportMethod: "sni-only"
}
}
}).dependsOn(["ClientBucket", "ClientOriginAccessIdentity"]);