question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't get port from RDS DatabaseCluster Endpoint

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:17 (11 by maintainers)

github_iconTop GitHub Comments

12reactions
skinny85commented, Jan 22, 2021

@balupraveendatty maybe you’re missing a call to Token.asString() somewhere where you’re passing the port directly as a number, where a string is expected? For example, this works for me:

        const vpc = new ec2.Vpc(this, 'Vpc');
        const db = new rds.DatabaseCluster(this, "Database", {
            engine: rds.DatabaseClusterEngine.auroraPostgres({
                version: rds.AuroraPostgresEngineVersion.VER_10_7,
            }),
            instanceProps: {
                vpc,
            },
        });
        new cdk.CfnOutput(this, 'Output', {
            value: cdk.Token.asString(db.clusterEndpoint.port),
        });

Produces:

Outputs:
  Output:
    Value:
      Fn::GetAtt:
        - DatabaseB269D8BB
        - Endpoint.Port
6reactions
dekozacommented, Jun 12, 2020

The problem is still present on 1.45.0 - I get port number -1.8881545897087736e+289 instead of 3306. Looks like overflow.

Read more comments on GitHub >

github_iconTop Results From Across the Web

class DatabaseCluster (construct) · AWS CDK
Create a clustered database with a given number of instances. Example. declare const vpc: ec2.Vpc; const cluster = new rds ...
Read more >
CreateDBCluster - Amazon Relational Database Service
The port number on which the instances in the DB cluster accept connections. RDS for MySQL and Aurora MySQL. Default: 3306. Valid values:...
Read more >
@aws-cdk/aws-rds - npm
DatabaseCluster (this, 'Database', { engine: rds. ... RDS databases have a default port, so you don't need to specify the port:.
Read more >
Getting started with AWS RDS Aurora DB Clusters - SQLShack
We are going to keep all the default values for the network configuration of this AWS RDS Aurora Cluster. The default database port...
Read more >
What the difference between rds.DatabaseInstance and rds ...
public readonly dbCluster: rds.DatabaseCluster | rds.DatabaseInstance; constructor(scope: Construct, id: string, props?: StackProps) { ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found