Describe the bug
I can't pass the RDS port from one stack to another.
I open a question on StackOverflow about it, but now I think it's actually a bug.
To Reproduce
class DbStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props: { vpc: ec2.Vpc }) {
super(scope, id);
const { vpc } = props;
const db = new DatabaseCluster(this, "Database", {
engine: rds.DatabaseClusterEngine.AuroraPostgresql,
engineVersion: "10.7",
masterUser: {
username: "admin",
},
defaultDatabaseName: "main",
instanceProps: {
instanceType: new ec2.InstanceType("r5.large"),
vpcSubnets: {
subnetType: ec2.SubnetType.Private,
},
vpc,
},
storageEncrypted: true,
parameterGroup: {
parameterGroupName: "default.aurora-postgresql10",
} as any,
});
console.log(db.clusterEndpoint);
console.log(db.clusterEndpoint.hostname);
console.log(db.clusterEndpoint.port);
console.log(db.clusterEndpoint.socketAddress);
}
}
The console output is:
Endpoint {
hostname: '${Token[Resource.Endpoint.Address.148]}',
port: -1.8881545897087827e+289,
socketAddress: '${Token[Resource.Endpoint.Address.148]}:{IndirectPort}' }
${Token[Resource.Endpoint.Address.148]}
-1.8881545897087827e+289
${Token[Resource.Endpoint.Address.148]}:{IndirectPort}
Expected behavior
I need a way to determine the port.
Version:
This might be a duplicate of https://github.com/awslabs/aws-cdk/issues/2679, but not exactly.
Just confirmed. Still happening in v0.34
+1 for this, seeing the same behavior
This should be fixed in the next release, as a temporary workaround in v0.34.0 you can do this to use the socketAddress somewhere
const socketAddress = `${db.clusterEndpoint.hostname}:${new cdk.Token(db.clusterEndpoint.port)}`;
The problem is still present on 1.45.0 - I get port number -1.8881545897087736e+289 instead of 3306. Looks like overflow.
Most helpful comment
The problem is still present on 1.45.0 - I get port number
-1.8881545897087736e+289instead of3306. Looks like overflow.