Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(route53): allow records with a weight of 0 #29595

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@
"Type": "A",
"Weight": 50
}
},
"WeightedRecord328406D0A": {
"Type": "AWS::Route53::RecordSet",
"Properties": {
"HostedZoneId": {
"Ref": "HostedZoneDB99F866"
},
"Name": "www.cdk.dev.",
"ResourceRecords": [
"4.5.6.7"
],
"SetIdentifier": "WEIGHT_0_ID_weightedrecordWeightedRecord37AA25819",
"TTL": "10",
"Type": "A",
"Weight": 0
}
}
},
"Parameters": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class TestStack extends Stack {
{ target: '1.2.3.4', weight: 20 },
{ target: '2.3.4.5', weight: 30 },
{ target: '3.4.5.6', weight: 50 },
{ target: '4.5.6.7', weight: 0 },
].forEach((data, index) => {
new route53.ARecord(this, `WeightedRecord${index}`, {
zone: hostedZone,
Expand Down
4 changes: 2 additions & 2 deletions packages/aws-cdk-lib/aws-route53/lib/record-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ export class RecordSet extends Resource implements IRecordSet {
if (props.setIdentifier && (props.setIdentifier.length < 1 || props.setIdentifier.length > 128)) {
throw new Error(`setIdentifier must be between 1 and 128 characters long, got: ${props.setIdentifier.length}`);
}
if (props.setIdentifier && !props.weight && !props.geoLocation && !props.region && !props.multiValueAnswer) {
if (props.setIdentifier && props.weight === undefined && !props.geoLocation && !props.region && !props.multiValueAnswer) {
throw new Error('setIdentifier can only be specified for non-simple routing policies');
}
if (props.multiValueAnswer && props.target.aliasTarget) {
Expand Down Expand Up @@ -405,7 +405,7 @@ export class RecordSet extends Resource implements IRecordSet {
return identifier;
}

if (this.weight) {
if (this.weight !== undefined) {
const idPrefix = `WEIGHT_${this.weight}_ID_`;
return this.createIdentifier(idPrefix);
}
Expand Down
33 changes: 33 additions & 0 deletions packages/aws-cdk-lib/aws-route53/test/record-set.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,39 @@ describe('record set', () => {
});
});

test('with weight of 0', () => {
// GIVEN
const stack = new Stack();

const zone = new route53.HostedZone(stack, 'HostedZone', {
zoneName: 'myzone',
});

// WHEN
new route53.RecordSet(stack, 'RecordSet', {
zone,
recordName: 'www',
recordType: route53.RecordType.CNAME,
target: route53.RecordTarget.fromValues('zzz'),
weight: 0,
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Route53::RecordSet', {
Name: 'www.myzone.',
Type: 'CNAME',
HostedZoneId: {
Ref: 'HostedZoneDB99F866',
},
ResourceRecords: [
'zzz',
],
TTL: '1800',
Weight: 0,
SetIdentifier: 'WEIGHT_0_ID_RecordSet',
});
});

test.each([
[-1],
[256],
Expand Down