aws-cdk: Can't get port from RDS DatabaseCluster Endpoint
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:
- OS: Linux
- Programming Language: Typescript
- CDK Version: 0.33.0
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 2
- Comments: 17 (11 by maintainers)
Commits related to this issue
- fix(rds): fix unresolved endpoint socket address The port needs to be passed as a string to the `Endpoint` class otherwise the concatenation of address and port does not resolve correctly (forced str... — committed to jogold/aws-cdk by jogold 5 years ago
- fix(rds): fix unresolved endpoint socket address The port needs to be passed as a string to the `Endpoint` class otherwise the concatenation of address and port does not resolve correctly (forced str... — committed to jogold/aws-cdk by jogold 5 years ago
- fix(rds): fix unresolved endpoint socket address Convert port to a string token before using it in `socketAddress` otherwise the number token is converted to a string and cannot be resolved. Fixes #... — committed to jogold/aws-cdk by jogold 5 years ago
- fix(rds): fix unresolved endpoint socket address (#2846) Convert port to a string token before using it in `socketAddress` otherwise the number token is converted to a string and cannot be resolved.... — committed to aws/aws-cdk by jogold 5 years ago
@balupraveendatty maybe you’re missing a call to
Token.asString()somewhere where you’re passing theportdirectly as a number, where a string is expected? For example, this works for me:Produces:
The problem is still present on 1.45.0 - I get port number
-1.8881545897087736e+289instead of3306. Looks like overflow.not
Token.toStringbutcdk.Token.asStringwhich you earlier mentioned. 😃Right. Exactly like I said in https://github.com/aws/aws-cdk/issues/2711#issuecomment-765628398, the code should be:
, not:
@moltar https://github.com/aws/aws-cdk/issues/2711#issuecomment-765628398
Thanks @skinny85 , you saved me 🥰
Nice one, cheers @skinny85