(rds/docdb): fromDatabaseInstanceAttributes stringifies number tokens incorrectly
See original GitHub issueWhen 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: databaseUrl
Environment
- 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: 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 https://github.com/aws/aws-cdk/issues/3448 and https://github.com/aws/aws-cdk/issues/10228 and https://github.com/aws/aws-cdk/issues/7126 and https://github.com/aws/aws-cdk/issues/9413?
The workaround for https://github.com/aws/aws-cdk/issues/9413 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:
- Created 3 years ago
- Comments:9 (6 by maintainers)
Top GitHub Comments
That would be helpful @john-kontralto !
⚠️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.