Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(aws-rds): Unable to use CfnParameter as port #17948

Closed
Lewenhaupt opened this issue Dec 10, 2021 · 6 comments · Fixed by #17995
Closed

(aws-rds): Unable to use CfnParameter as port #17948

Lewenhaupt opened this issue Dec 10, 2021 · 6 comments · Fixed by #17995
Labels
@aws-cdk/aws-rds Related to Amazon Relational Database bug This issue is a bug. effort/small Small work item – less than a day of effort p1

Comments

@Lewenhaupt
Copy link

Lewenhaupt commented Dec 10, 2021

What is the problem?

CfnParameters cannot be used for the port value of a DatabaseInstance in aws-rds. The value requires only a number and valueAsNumber on a CfnParameter doesn't produce a valid number on synthesis.
"Port": "-1.8881545897088186e+289"
instead of
"ToPort": { "Ref": "DBPort" } (as it becomes for a security group)
https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_rds.DatabaseInstance.html

Reproduction Steps

const dbPort = new CfnParameter(this, 'DBPort', {
  type: 'Number',
  default: 5432
})

const postgresDb = new rds.DatabaseInstance(this, 'PostgresDb', {
      port: dbPort.valueAsNumber,
})

What did you expect to happen?

Expected that the generated cfn-template would have the port parameter as a reference to the cfn parameter

What actually happened?

The port parameter was set to a static value: -1.8881545897088186e+289

CDK CLI Version

2.0.0 (build 4b6ce31)

Framework Version

No response

Node.js Version

v16.9.1

OS

mac os

Language

Typescript

Language Version

No response

Other information

No response

@Lewenhaupt Lewenhaupt added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 10, 2021
@github-actions github-actions bot added the @aws-cdk/aws-rds Related to Amazon Relational Database label Dec 10, 2021
@ryparker ryparker added needs-reproduction This issue needs reproduction. p2 labels Dec 10, 2021
@skinny85
Copy link
Contributor

@ryparker you want to try and reproduce this one?

@ryparker
Copy link
Contributor

Was able to reproduce this with the following code (using cdk ^1.135.0):

import { App, Stack, CfnParameter } from '@aws-cdk/core';
import { DatabaseInstance, DatabaseInstanceEngine } from '@aws-cdk/aws-rds';
import { Vpc, SubnetType } from '@aws-cdk/aws-ec2';


const app = new App();

const stack = new Stack(app, 'sampleRds', {
  env: {
    account: process.env.CDK_DEFAULT_ACCOUNT,
    region: process.env.CDK_DEFAULT_REGION
  }
});

const dbPort = new CfnParameter(stack, 'DBPort', {
  type: 'Number',
  default: 5432
})

const vpc = Vpc.fromLookup(stack, 'Vpc', {
  isDefault: true
})

const postgresDb = new DatabaseInstance(stack, 'PostgresDb', {
  port: dbPort.valueAsNumber,
  vpc,
  engine: DatabaseInstanceEngine.POSTGRES,
  vpcSubnets: {
    subnetType: SubnetType.PUBLIC
  }
})

CloudFormation output:

PostgresDb29EB1611:
    Type: AWS::RDS::DBInstance
    Properties:
      ...
      Port: "-1.888154589708827e+289"

@ryparker ryparker added p1 and removed needs-reproduction This issue needs reproduction. p2 labels Dec 10, 2021
@skinny85
Copy link
Contributor

Thnx!

@jumic
Copy link
Contributor

jumic commented Dec 11, 2021

From my point of view, this is caused by props.port?.toString() in Instances.ts. We should replace it by Tokenization.stringifyNumber(props.port).

@skinny85 Are you working on it (because this issue is assigned to you)? If not, I can fix it and submit a PR.

@skinny85
Copy link
Contributor

That would be awesome if you could work on this @jumic!

@skinny85 skinny85 added effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels Dec 13, 2021
@skinny85 skinny85 removed their assignment Dec 13, 2021
@mergify mergify bot closed this as completed in #17995 Dec 15, 2021
mergify bot pushed a commit that referenced this issue Dec 15, 2021
In `DatabaseInstance` the port number can be specified using data type number.
If a token value (e.g. CloudFormation Parameter) was used here, the token was not resolved correctly.

The conversion of property `port` has been corrected by using method `Tokenization.stringifyNumber()`.

Fixes #17948.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

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.

TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this issue Feb 21, 2022
In `DatabaseInstance` the port number can be specified using data type number.
If a token value (e.g. CloudFormation Parameter) was used here, the token was not resolved correctly.

The conversion of property `port` has been corrected by using method `Tokenization.stringifyNumber()`.

Fixes aws#17948.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-rds Related to Amazon Relational Database bug This issue is a bug. effort/small Small work item – less than a day of effort p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants