Skip to content

aws-route53: Creating a RecordSet with weight of zero throws an Error #29556

@brandonjs

Description

@brandonjs

Describe the bug

When creating an ARecord object in Route53 with props.weight set to 0 an Error is thrown.

Expected Behavior

The record would be created with weight zero which is a valid value.

Current Behavior

An Error is thrown:

The issue is that when props.weight = 0, !props.weight in Javascript becomes !0 which evaluates as true.

$ node
Welcome to Node.js v18.15.0.
Type ".help" for more information.
> !0
true

Reproduction Steps

Create an ARecord object with weight of zero:

new ARecord(this, "ARecord", {
    zone: publicHostedZone,
    recordName: "myendpoint.example.com,
    target: RecordTarget.fromAlias(new LoadBalancerTarget(loadBalancer)),
    weight: 0,
    setIdentifier: "ALB",
});

And run cdk synth.

Possible Solution

Change !props.weight to props.weight === undefined.

Additional Information/Context

Bug introduced in 1.124

CDK CLI Version

^2.132.1

Framework Version

No response

Node.js Version

18.18.2

OS

Any

Language

TypeScript

Language Version

No response

Other information

Error: setIdentifier can only be specified for non-simple routing policies
    at new RecordSet (/redacted/node_modules/aws-cdk-lib/aws-route53/lib/record-set.js:1:3773)
    at new ARecord (/redacted/node_modules/aws-cdk-lib/aws-route53/lib/record-set.js:1:7348)
    at EcsClusterStack.createLoadBalancer (/redacted/dist/lib/stacks/api_service/ecs_cluster.js:126:9)
    at new EcsClusterStack (/redacted/dist/lib/stacks/api_service/ecs_cluster.js:29:34)
    at new ApiService (/redacted/dist/lib/constructs/api_service.js:34:30)
    at addDeploymentGroupsToPipelineStage (/redacted/dist/lib/app.js:200:28)
    at /redacted/dist/lib/app.js:85:9
    at Array.forEach (<anonymous>)
    at /redacted/dist/lib/app.js:84:21
    at Array.forEach (<anonymous>)

Node.js v18.18.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-route53Related to Amazon Route 53bugThis issue is a bug.effort/smallSmall work item – less than a day of effortp1

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions