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.

(rds/docdb): fromDatabaseInstanceAttributes stringifies number tokens incorrectly

See original GitHub issue

When using a number token (from a CfnParamater of type Number) to create a DatabaseInstance with fromDatabaseInstanceAttributes, the token renders as an invalid literal in the template.

Reproduction Steps

    const existingDatabaseUrl = new CfnParameter(this, 'ExistingDatabaseUrl', {
      default: '',
    const existingDatabasePort = new CfnParameter(this, 'ExistingDatabasePort', {
      type: 'Number',
      default: 5432,
    const existingInstanceId = new CfnParameter(this, 'ExistingInstanceId', {
      default: '',

    const existingDatabaseInstance = DatabaseInstance.fromDatabaseInstanceAttributes(this, 'ExistingDatabaseInstance', {
      instanceIdentifier: existingInstanceId,
      securityGroups: [],
      instanceEndpointAddress: existingDatabaseUrl,
      port: existingDatabasePort,

  new CfnOutput(scope, `DatabaseUrlOutput`, {
    exportName: 'databaseUrl',
    value: `${existingDatabaseInstance.dbInstanceEndpointAddress}:${existingDatabaseInstance.dbInstanceEndpointPort}`,

What did you expect to happen?

The synthesized template for the output would create a Ref for the value

What actually happened?

        - ""
        - - Ref: ExistingDatabaseUrl
          - :-1.888154589708849e+289
      Name: databaseUrl


  • CDK CLI Version : 1.75.0 (build 7708242)
  • Framework Version: 1.75.0
  • Node.js Version: v12.16.2
  • OS : OS X 10.14.6
  • Language (Version): TypeScript 3.9.7


Explicitly using Fn.join in the Output value causes a similar result:

  new CfnOutput(scope, `${idPrefix}DatabaseUrlOutput`, {
    exportName: 'databaseUrl',
    value: Fn.join(':', [instance.dbInstanceEndpointAddress, instance.dbInstanceEndpointPort]),
    // value: `${instance.dbInstanceEndpointAddress}:${instance.dbInstanceEndpointPort}`,


        - ":"
        - - Ref: ExistingDatabaseUrl
          - "-1.888154589708849e+289"
      Name: databaseUrl

It looks like valueAsNumber is not returning a token, but instead a literal.

If I tell CDK to log that value after creating it, I see -1.888154589708849e+289 instead of something like ${Token[TOKEN.456]}

Related to and and and

The workaround for doesn’t apply for something like a DB Instance port because there’s no analog to Schedule.expression

This is 🐛 Bug Report

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

skinny85commented, Dec 7, 2020

That would be helpful @john-kontralto !

github-actions[bot]commented, Aug 31, 2021


Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tokens - AWS Cloud Development Kit (AWS CDK) v2
The following example validates that a string value, which could be a token, is no more than 10 characters long.
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 Post

No results found

github_iconTop Related Hashnode Post

No results found