Skip to content

Commit ca59616

Browse files
fix(rds): DatabaseCluster.instanceEndpoints doesn't include writer endpoint (#29337)
### Issue # (if applicable) Closes #29279. ### Reason for this change `DatabaseCluster.instanceEndpoints` should include writer's endpoint but doesn't. ### Description of changes Add writer's endpoint to `DatabaseCluster.instanceEndpoints` ### Description of how you validated changes Add unit tests ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 3bb2944 commit ca59616

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed

packages/aws-cdk-lib/aws-rds/lib/cluster.ts

+1
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,7 @@ abstract class DatabaseClusterNew extends DatabaseClusterBase {
756756
promotionTier: 0, // override the promotion tier so that writers are always 0
757757
});
758758
instanceIdentifiers.push(writer.instanceIdentifier);
759+
instanceEndpoints.push(new Endpoint(writer.dbInstanceEndpointAddress, this.clusterEndpoint.port));
759760

760761
(props.readers ?? []).forEach(instance => {
761762
const clusterInstance = instance.bind(this, this, {

packages/aws-cdk-lib/aws-rds/test/cluster.test.ts

+97
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,103 @@ describe('cluster new api', () => {
528528
});
529529
});
530530

531+
describe('instanceEndpoints', () => {
532+
test('should contain writer and reader instance endpoints at DatabaseCluster', () => {
533+
//GIVEN
534+
const stack = testStack();
535+
const vpc = new ec2.Vpc(stack, 'VPC');
536+
537+
//WHEN
538+
const cluster = new DatabaseCluster(stack, 'Database', {
539+
engine: DatabaseClusterEngine.AURORA,
540+
vpc,
541+
writer: ClusterInstance.serverlessV2('writer'),
542+
readers: [ClusterInstance.serverlessV2('reader')],
543+
iamAuthentication: true,
544+
});
545+
546+
//THEN
547+
expect(cluster.instanceEndpoints).toHaveLength(2);
548+
expect(stack.resolve(cluster.instanceEndpoints)).toEqual([{
549+
hostname: {
550+
'Fn::GetAtt': ['Databasewriter2462CC03', 'Endpoint.Address'],
551+
},
552+
port: {
553+
'Fn::GetAtt': ['DatabaseB269D8BB', 'Endpoint.Port'],
554+
},
555+
socketAddress: {
556+
'Fn::Join': ['', [
557+
{ 'Fn::GetAtt': ['Databasewriter2462CC03', 'Endpoint.Address'] },
558+
':',
559+
{ 'Fn::GetAtt': ['DatabaseB269D8BB', 'Endpoint.Port'] },
560+
]],
561+
},
562+
}, {
563+
hostname: {
564+
'Fn::GetAtt': ['Databasereader13B43287', 'Endpoint.Address'],
565+
},
566+
port: {
567+
'Fn::GetAtt': ['DatabaseB269D8BB', 'Endpoint.Port'],
568+
},
569+
socketAddress: {
570+
'Fn::Join': ['', [
571+
{ 'Fn::GetAtt': ['Databasereader13B43287', 'Endpoint.Address'] },
572+
':',
573+
{ 'Fn::GetAtt': ['DatabaseB269D8BB', 'Endpoint.Port'] },
574+
]],
575+
},
576+
}]);
577+
});
578+
579+
test('should contain writer and reader instance endpoints at DatabaseClusterFromSnapshot', () => {
580+
//GIVEN
581+
const stack = testStack();
582+
const vpc = new ec2.Vpc(stack, 'VPC');
583+
584+
//WHEN
585+
const cluster = new DatabaseClusterFromSnapshot(stack, 'Database', {
586+
engine: DatabaseClusterEngine.AURORA,
587+
vpc,
588+
snapshotIdentifier: 'snapshot-identifier',
589+
iamAuthentication: true,
590+
writer: ClusterInstance.serverlessV2('writer'),
591+
readers: [ClusterInstance.serverlessV2('reader')],
592+
});
593+
594+
//THEN
595+
expect(cluster.instanceEndpoints).toHaveLength(2);
596+
expect(stack.resolve(cluster.instanceEndpoints)).toEqual([{
597+
hostname: {
598+
'Fn::GetAtt': ['Databasewriter2462CC03', 'Endpoint.Address'],
599+
},
600+
port: {
601+
'Fn::GetAtt': ['DatabaseB269D8BB', 'Endpoint.Port'],
602+
},
603+
socketAddress: {
604+
'Fn::Join': ['', [
605+
{ 'Fn::GetAtt': ['Databasewriter2462CC03', 'Endpoint.Address'] },
606+
':',
607+
{ 'Fn::GetAtt': ['DatabaseB269D8BB', 'Endpoint.Port'] },
608+
]],
609+
},
610+
}, {
611+
hostname: {
612+
'Fn::GetAtt': ['Databasereader13B43287', 'Endpoint.Address'],
613+
},
614+
port: {
615+
'Fn::GetAtt': ['DatabaseB269D8BB', 'Endpoint.Port'],
616+
},
617+
socketAddress: {
618+
'Fn::Join': ['', [
619+
{ 'Fn::GetAtt': ['Databasereader13B43287', 'Endpoint.Address'] },
620+
':',
621+
{ 'Fn::GetAtt': ['DatabaseB269D8BB', 'Endpoint.Port'] },
622+
]],
623+
},
624+
}]);
625+
});
626+
});
627+
531628
describe('provisioned writer with serverless readers', () => {
532629
test('serverless reader in promotion tier 2 throws warning', () => {
533630
// GIVEN

0 commit comments

Comments
 (0)