-
Notifications
You must be signed in to change notification settings - Fork 4.5k
(rds/docdb): fromDatabaseInstanceAttributes stringifies number tokens incorrectly #11813
Copy link
Copy link
Closed
Labels
@aws-cdk/coreRelated to core CDK functionalityRelated to core CDK functionalitybugThis issue is a bug.This issue is a bug.effort/smallSmall work item – less than a day of effortSmall work item – less than a day of effortp2
Description
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: '',
}).valueAsString;
const existingDatabasePort = new CfnParameter(this, 'ExistingDatabasePort', {
type: 'Number',
default: 5432,
}).valueAsNumber;
const existingInstanceId = new CfnParameter(this, 'ExistingInstanceId', {
default: '',
}).valueAsString;
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?
DatabaseUrlOutput:
Value:
Fn::Join:
- ""
- - Ref: ExistingDatabaseUrl
- :-1.888154589708849e+289
Export:
Name: databaseUrlEnvironment
- 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
Other
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}`,
});synthesizes:
ExistingDatabaseUrlOutput:
Value:
Fn::Join:
- ":"
- - Ref: ExistingDatabaseUrl
- "-1.888154589708849e+289"
Export:
Name: databaseUrlIt 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 #3448 and #10228 and #7126 and #9413?
The workaround for #9413 doesn't apply for something like a DB Instance port because there's no analog to Schedule.expression
This is 🐛 Bug Report
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
@aws-cdk/coreRelated to core CDK functionalityRelated to core CDK functionalitybugThis issue is a bug.This issue is a bug.effort/smallSmall work item – less than a day of effortSmall work item – less than a day of effortp2