-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.ts
77 lines (70 loc) · 2.12 KB
/
util.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
66
67
68
69
70
71
72
73
74
75
76
77
import * as pulumi from '@pulumi/pulumi';
import * as aws from '@pulumi/aws';
type Zonelike = aws.route53.GetZoneResult | aws.route53.Zone;
export const dnsValidatedCertificate = (zone: Zonelike, domain: string): aws.acm.Certificate => {
const certificate = new aws.acm.Certificate(domain, {
domainName: domain,
validationMethod: 'DNS'
});
const records: aws.route53.Record[] = [];
certificate.domainValidationOptions.apply(options => {
for (const option of options) {
records.push(new aws.route53.Record(
`${option.domainName}-validation`,
{
zoneId: zone.zoneId,
name: option.resourceRecordName,
type: option.resourceRecordType,
records: [option.resourceRecordValue],
ttl: 60
}
));
}
});
const certificateValidation = new aws.acm.CertificateValidation(domain, {
certificateArn: certificate.arn,
validationRecordFqdns: records.map(record => record.fqdn)
});
return certificate;
};
const staticMethods = ['GET', 'HEAD', 'OPTIONS'];
export const staticWebsiteDistribution = (domain: string, website: aws.s3.BucketWebsiteConfigurationV2, certificate: aws.acm.Certificate): aws.cloudfront.Distribution => {
return new aws.cloudfront.Distribution(domain, {
defaultCacheBehavior: {
allowedMethods: staticMethods,
cachedMethods: staticMethods,
targetOriginId: domain,
viewerProtocolPolicy: 'allow-all',
forwardedValues: {
queryString: false,
cookies: {
forward: 'none'
}
}
},
enabled: true,
origins: [{
domainName: website.websiteEndpoint,
originId: domain,
customOriginConfig: {
httpPort: 80,
httpsPort: 443,
originProtocolPolicy: 'http-only',
originSslProtocols: ['SSLv3', 'TLSv1', 'TLSv1.1', 'TLSv1.2']
}
}],
restrictions: {
geoRestriction: {
restrictionType: 'none'
}
},
viewerCertificate: {
acmCertificateArn: certificate.arn,
sslSupportMethod: 'sni-only',
minimumProtocolVersion: 'TLSv1.2_2021'
},
aliases: [
domain
]
});
};