diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.weighted-record.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.weighted-record.js.snapshot/manifest.json index 19af9778152e4..3519a94475777 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.weighted-record.js.snapshot/manifest.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.weighted-record.js.snapshot/manifest.json @@ -18,7 +18,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/aaa3e08f1a3f807fd7d4163e5ad01d2400b1f162ead6be3e788281f64fb3f021.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/fddf2231120b2ab1d4ba478e288bd5dc0dcd2894203701b20412238cc1d93663.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -58,6 +58,12 @@ "data": "WeightedRecord2D4D415A2" } ], + "/weighted-record/WeightedRecord3/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "WeightedRecord328406D0A" + } + ], "/weighted-record/BootstrapVersion": [ { "type": "aws:cdk:logicalId", diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.weighted-record.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.weighted-record.js.snapshot/tree.json index 29e50fd5b0cd2..20d4948008ee8 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.weighted-record.js.snapshot/tree.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.weighted-record.js.snapshot/tree.json @@ -134,6 +134,40 @@ "version": "0.0.0" } }, + "WeightedRecord3": { + "id": "WeightedRecord3", + "path": "weighted-record/WeightedRecord3", + "children": { + "Resource": { + "id": "Resource", + "path": "weighted-record/WeightedRecord3/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Route53::RecordSet", + "aws:cdk:cloudformation:props": { + "hostedZoneId": { + "Ref": "HostedZoneDB99F866" + }, + "name": "www.cdk.dev.", + "resourceRecords": [ + "4.5.6.7" + ], + "setIdentifier": "WEIGHT_0_ID_weightedrecordWeightedRecord37AA25819", + "ttl": "10", + "type": "A", + "weight": 0 + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_route53.CfnRecordSet", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_route53.ARecord", + "version": "0.0.0" + } + }, "BootstrapVersion": { "id": "BootstrapVersion", "path": "weighted-record/BootstrapVersion", diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.weighted-record.js.snapshot/weighted-record.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.weighted-record.js.snapshot/weighted-record.assets.json index 09cc2ad6e14b8..844a8326cdbe0 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.weighted-record.js.snapshot/weighted-record.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.weighted-record.js.snapshot/weighted-record.assets.json @@ -1,7 +1,7 @@ { "version": "36.0.0", "files": { - "aaa3e08f1a3f807fd7d4163e5ad01d2400b1f162ead6be3e788281f64fb3f021": { + "fddf2231120b2ab1d4ba478e288bd5dc0dcd2894203701b20412238cc1d93663": { "source": { "path": "weighted-record.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "aaa3e08f1a3f807fd7d4163e5ad01d2400b1f162ead6be3e788281f64fb3f021.json", + "objectKey": "fddf2231120b2ab1d4ba478e288bd5dc0dcd2894203701b20412238cc1d93663.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.weighted-record.js.snapshot/weighted-record.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.weighted-record.js.snapshot/weighted-record.template.json index 245ed234bbc91..f4e1924101057 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.weighted-record.js.snapshot/weighted-record.template.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.weighted-record.js.snapshot/weighted-record.template.json @@ -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": { diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.weighted-record.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.weighted-record.ts index 7c6d9a3aa299b..d5b3a7c128ec6 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.weighted-record.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-route53/test/integ.weighted-record.ts @@ -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, diff --git a/packages/aws-cdk-lib/aws-route53/lib/record-set.ts b/packages/aws-cdk-lib/aws-route53/lib/record-set.ts index 499b3ca12c5a3..65e102e1e32a8 100644 --- a/packages/aws-cdk-lib/aws-route53/lib/record-set.ts +++ b/packages/aws-cdk-lib/aws-route53/lib/record-set.ts @@ -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) { @@ -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); } diff --git a/packages/aws-cdk-lib/aws-route53/test/record-set.test.ts b/packages/aws-cdk-lib/aws-route53/test/record-set.test.ts index 4f04cdea52eaf..a8f717e4b0242 100644 --- a/packages/aws-cdk-lib/aws-route53/test/record-set.test.ts +++ b/packages/aws-cdk-lib/aws-route53/test/record-set.test.ts @@ -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],