generated from szikszail/npm-package
/
route53.ts
142 lines (129 loc) · 3.99 KB
/
route53.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
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
139
140
141
142
import { Match, Matcher } from "aws-cdk-lib/assertions";
import { CfnHostedZone, CfnRecordSet, RecordType } from "aws-cdk-lib/aws-route53";
import { AdvancedMatcher } from "./advanced-matcher";
import { AdvancedTemplate } from "./advanced-template"
import { ApiGatewayDomain } from "./apigateway";
import { CloudFrontDistribution } from "./cloudfront";
import { RemovableResource } from "./resource";
/**
* A test construct representing a Route53 RecordSet.
* @see {@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_route53.CfnHostedZone.html}
*/
export class Route53HostedZone extends RemovableResource {
constructor(template: AdvancedTemplate, props?: any) {
super(CfnHostedZone.CFN_RESOURCE_TYPE_NAME, template, props);
}
/**
* Sets a matching name for the HostedZone
* @param name Either the whole or a partial name of the record
* @returns
*/
public withName(name: string) {
this.withProperty('Name', Match.stringLikeRegexp(name));
return this;
}
}
/**
* A test construct representing a Route53 RecordSet.
* @see {@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_route53.CfnRecordSet.html}
*/
export class Route53RecordSet extends RemovableResource {
constructor(template: AdvancedTemplate, props?: any) {
super(CfnRecordSet.CFN_RESOURCE_TYPE_NAME, template, props);
}
/**
* Sets a matching RecordType
* @see {@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_route53.RecordType.html}
* @param recordType The records type to match
* @returns
*/
public withRecordType(recordType: RecordType) {
this.withProperty('Type', recordType);
return this;
}
/**
* Sets a matching name for the RecordSet
* @param name Either the whole or a partial name of the record
* @returns
*/
public withName(name: string) {
this.withProperty('Name', Match.stringLikeRegexp(name));
return this;
}
/**
* Sets a matching hosted zone ID for the RecordSet
* @param zone Either the hosted zone resource, a matcher, or a matching zone Id.
* @returns
*/
/*
TODO: add mapping
"HostedZoneId": {
"Fn::FindInMap": [
"AWSCloudFrontPartitionHostedZoneIdMap",
{
"Ref": "AWS::Partition"
},
"zoneId"
]
}
"Mappings": {
"AWSCloudFrontPartitionHostedZoneIdMap": {
"aws": {
"zoneId": "Z2FDTNDATAQYW2"
},
"aws-cn": {
"zoneId": "Z3RFFRIM2A3IF5"
}
}
},
*/
public inHostedZone(zone: Route53HostedZone | Matcher) {
if (zone instanceof Route53HostedZone) {
this.withProperty('HostedZoneId', zone.ref);
} else {
this.withProperty('HostedZoneId', zone);
}
return this;
}
/**
* Sets a matching CloudFront Distribution target for the RecordSet
* @param distribution The CloudFront distribution as the target
* @returns
*/
public withAliasToCloudFront(distribution: CloudFrontDistribution) {
this.withProperty('AliasTarget', Match.objectLike({
DNSName: AdvancedMatcher.fnGetAtt(distribution.id, "DomainName"),
}));
return this;
}
/**
* Sets a matching ApiGateway DomainName target for the RecordSet
* @param domain The ApiGateway DomainName as the target
* @returns
*/
public withAliasToApiGatewayDomain(domain: ApiGatewayDomain) {
this.withProperty('AliasTarget', Match.objectLike({
DNSName: AdvancedMatcher.fnGetAtt(domain.id, "RegionalDomainName"),
}));
return this;
}
/**
* Sets a matching S3 Bucket target for the RecordSet
* @returns
*/
public withAliasToS3() {
this.withProperty('AliasTarget', Match.objectLike({
DNSName: `s3-website.${this.template.region}.amazonaws.com`,
}));
return this;
}
/**
* Sets matching resource records for the RecordSet
* @param records The list of records
* @returns
*/
public withResourceRecords(records: string[]) {
this.withProperty('ResourceRecords', Match.arrayWith(records));
return this;
}
}