-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
88 lines (73 loc) · 2.44 KB
/
index.js
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
"use strict";
const pulumi = require("@pulumi/pulumi");
const aws = require("@pulumi/aws");
const config = new pulumi.Config('infra')
let envName = config.require('envName')
let uiDomain = config.require('uiDomain')
let certificateArn = config.require('certificateArn')
// Create an AWS resource (S3 Bucket)
const uiContentBucket = new aws.s3.Bucket(`${envName}-ui-content-bucket`, {
website: { indexDocument: 'index.html' }
});
exports.uiContentBucketName = uiContentBucket.id;
exports.uiContentBucketEndpoint = pulumi.interpolate`http://${uiContentBucket.websiteEndpoint}`;
const logBucket = new aws.s3.Bucket(`${envName}-request-logs`, {
acl: "private",
});
const aliases = uiDomain.split('.').length == 2
? [uiDomain, `www.${uiDomain}`]
: [uiDomain]
const cdnDistro = new aws.cloudfront.Distribution(`${envName}-distribution`, {
enabled: true,
aliases,
origins: [{
originId: uiContentBucket.arn,
domainName: uiContentBucket.websiteEndpoint,
customOriginConfig: {
originProtocolPolicy: "http-only",
httpPort: 80,
httpsPort: 443,
originSslProtocols: ["TLSv1.2"],
},
}],
// viewerCertificate: { cloudfrontDefaultCertificate: true },
viewerCertificate: {
// Per AWS, ACM certificate must be in the us-east-1 region.
acmCertificateArn: certificateArn,
sslSupportMethod: "sni-only",
},
defaultRootObject: "index.html",
defaultCacheBehavior: {
targetOriginId: uiContentBucket.arn,
viewerProtocolPolicy: "redirect-to-https",
allowedMethods: ["GET", "HEAD", "OPTIONS"],
cachedMethods: ["GET", "HEAD", "OPTIONS"],
forwardedValues: {
cookies: { forward: "none" },
queryString: false,
},
minTtl: 600,
defaultTtl: 3600,
maxTtl: 7200,
},
priceClass: "PriceClass_100",
customErrorResponses: [
{ errorCode: 404, responseCode: 200, responsePagePath: "/index.html" },
// S3 returns 403 when object isn't found
{ errorCode: 403, responseCode: 200, responsePagePath: "/index.html" },
],
loggingConfig: {
bucket: logBucket.bucketDomainName,
// False for now. Don't want to store anything sensitive in
// this bucket. Need to get a more sophisticated logging
// aproach that can filter out sensitive stuff
includeCookies: false,
prefix: `${uiDomain}/`,
},
restrictions: {
geoRestriction: {
restrictionType: "none",
},
},
});
exports.cloudfrontDomain = cdnDistro.domainName;