diff --git a/packages/@aws-cdk/aws-rds/lib/endpoint.ts b/packages/@aws-cdk/aws-rds/lib/endpoint.ts index 89f658b603236..4b66d44d034d0 100644 --- a/packages/@aws-cdk/aws-rds/lib/endpoint.ts +++ b/packages/@aws-cdk/aws-rds/lib/endpoint.ts @@ -25,7 +25,7 @@ export class Endpoint { this.hostname = address; this.port = port; - const portDesc = Token.isUnresolved(port) ? '{IndirectPort}' : port; + const portDesc = Token.isUnresolved(port) ? Token.asString(port) : port; this.socketAddress = `${address}:${portDesc}`; } } diff --git a/packages/@aws-cdk/aws-rds/test/test.instance.ts b/packages/@aws-cdk/aws-rds/test/test.instance.ts index 01e1a08b46610..7bcdabbc26165 100644 --- a/packages/@aws-cdk/aws-rds/test/test.instance.ts +++ b/packages/@aws-cdk/aws-rds/test/test.instance.ts @@ -375,6 +375,37 @@ export = { statistic: 'Average' }); + test.done(); + }, + + 'can resolve endpoint port and socket address'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'VPC'); + + // WHEN + const instance = new rds.DatabaseInstance(stack, 'Instance', { + engine: rds.DatabaseInstanceEngine.Mysql, + instanceClass: new ec2.InstanceTypePair(ec2.InstanceClass.Burstable2, ec2.InstanceSize.Small), + masterUsername: 'admin', + vpc + }); + + test.deepEqual(stack.resolve(instance.instanceEndpoint.port), { + 'Fn::GetAtt': ['InstanceC1063A87', 'Endpoint.Port'] + }); + + test.deepEqual(stack.resolve(instance.instanceEndpoint.socketAddress), { + 'Fn::Join': [ + '', + [ + { 'Fn::GetAtt': ['InstanceC1063A87', 'Endpoint.Address'] }, + ':', + { 'Fn::GetAtt': ['InstanceC1063A87', 'Endpoint.Port'] }, + ] + ] + }); + test.done(); } };