diff --git a/packages/@aws-cdk/aws-rds/lib/instance.ts b/packages/@aws-cdk/aws-rds/lib/instance.ts index d50dd0e4f8004..10467e0b19390 100644 --- a/packages/@aws-cdk/aws-rds/lib/instance.ts +++ b/packages/@aws-cdk/aws-rds/lib/instance.ts @@ -746,7 +746,7 @@ abstract class DatabaseInstanceNew extends DatabaseInstanceBase implements IData performanceInsightsRetentionPeriod: enablePerformanceInsights ? (props.performanceInsightRetention || PerformanceInsightRetention.DEFAULT) : undefined, - port: props.port ? Tokenization.stringifyNumber(props.port) : undefined, + port: props.port !== undefined ? Tokenization.stringifyNumber(props.port) : undefined, preferredBackupWindow: props.preferredBackupWindow, preferredMaintenanceWindow: props.preferredMaintenanceWindow, processorFeatures: props.processorFeatures && renderProcessorFeatures(props.processorFeatures), diff --git a/packages/@aws-cdk/aws-rds/test/instance.test.ts b/packages/@aws-cdk/aws-rds/test/instance.test.ts index 51c4de837690b..ae3972b7e9e19 100644 --- a/packages/@aws-cdk/aws-rds/test/instance.test.ts +++ b/packages/@aws-cdk/aws-rds/test/instance.test.ts @@ -1631,7 +1631,7 @@ describe('instance', () => { }); }); - test('instance with port', () => { + test('instance with port provided as a number', () => { // WHEN new rds.DatabaseInstance(stack, 'Database', { engine: rds.DatabaseInstanceEngine.MYSQL, @@ -1646,19 +1646,24 @@ describe('instance', () => { }); }); - test('instance with port from token', () => { + test('instance with port provided as a CloudFormation parameter', () => { + // GIVEN + const port = new cdk.CfnParameter(stack, 'Port', { + type: 'Number', + }).valueAsNumber; + // WHEN new rds.DatabaseInstance(stack, 'Database', { engine: rds.DatabaseInstanceEngine.MYSQL, instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.SMALL), vpc, - port: cdk.Token.asNumber({ Ref: 'port' }), + port, }); // THEN expect(stack).toHaveResourceLike('AWS::RDS::DBInstance', { Port: { - Ref: 'port', + Ref: 'Port', }, }); });