Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rds): DatabaseCluster.instanceEndpoints doesn't include writer endpoint #29337

Merged
merged 6 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/aws-cdk-lib/aws-rds/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,7 @@ abstract class DatabaseClusterNew extends DatabaseClusterBase {
promotionTier: 0, // override the promotion tier so that writers are always 0
});
instanceIdentifiers.push(writer.instanceIdentifier);
instanceEndpoints.push(new Endpoint(writer.dbInstanceEndpointAddress, this.clusterEndpoint.port));

(props.readers ?? []).forEach(instance => {
const clusterInstance = instance.bind(this, this, {
Expand Down
97 changes: 97 additions & 0 deletions packages/aws-cdk-lib/aws-rds/test/cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,103 @@ describe('cluster new api', () => {
});
});

describe('instanceEndpoints', () => {
test('should contain writer and reader instance endpoints at DatabaseCluster', () => {
//GIVEN
const stack = testStack();
const vpc = new ec2.Vpc(stack, 'VPC');

//WHEN
const cluster = new DatabaseCluster(stack, 'Database', {
engine: DatabaseClusterEngine.AURORA,
vpc,
writer: ClusterInstance.serverlessV2('writer'),
readers: [ClusterInstance.serverlessV2('reader')],
iamAuthentication: true,
});

//THEN
expect(cluster.instanceEndpoints).toHaveLength(2);
expect(stack.resolve(cluster.instanceEndpoints)).toEqual([{
hostname: {
'Fn::GetAtt': ['Databasewriter2462CC03', 'Endpoint.Address'],
},
port: {
'Fn::GetAtt': ['DatabaseB269D8BB', 'Endpoint.Port'],
},
socketAddress: {
'Fn::Join': ['', [
{ 'Fn::GetAtt': ['Databasewriter2462CC03', 'Endpoint.Address'] },
':',
{ 'Fn::GetAtt': ['DatabaseB269D8BB', 'Endpoint.Port'] },
]],
},
}, {
hostname: {
'Fn::GetAtt': ['Databasereader13B43287', 'Endpoint.Address'],
},
port: {
'Fn::GetAtt': ['DatabaseB269D8BB', 'Endpoint.Port'],
},
socketAddress: {
'Fn::Join': ['', [
{ 'Fn::GetAtt': ['Databasereader13B43287', 'Endpoint.Address'] },
':',
{ 'Fn::GetAtt': ['DatabaseB269D8BB', 'Endpoint.Port'] },
]],
},
}]);
});

test('should contain writer and reader instance endpoints at DatabaseClusterFromSnapshot', () => {
//GIVEN
const stack = testStack();
const vpc = new ec2.Vpc(stack, 'VPC');

//WHEN
const cluster = new DatabaseClusterFromSnapshot(stack, 'Database', {
engine: DatabaseClusterEngine.AURORA,
vpc,
snapshotIdentifier: 'snapshot-identifier',
iamAuthentication: true,
writer: ClusterInstance.serverlessV2('writer'),
readers: [ClusterInstance.serverlessV2('reader')],
});

//THEN
expect(cluster.instanceEndpoints).toHaveLength(2);
expect(stack.resolve(cluster.instanceEndpoints)).toEqual([{
hostname: {
'Fn::GetAtt': ['Databasewriter2462CC03', 'Endpoint.Address'],
},
port: {
'Fn::GetAtt': ['DatabaseB269D8BB', 'Endpoint.Port'],
},
socketAddress: {
'Fn::Join': ['', [
{ 'Fn::GetAtt': ['Databasewriter2462CC03', 'Endpoint.Address'] },
':',
{ 'Fn::GetAtt': ['DatabaseB269D8BB', 'Endpoint.Port'] },
]],
},
}, {
hostname: {
'Fn::GetAtt': ['Databasereader13B43287', 'Endpoint.Address'],
},
port: {
'Fn::GetAtt': ['DatabaseB269D8BB', 'Endpoint.Port'],
},
socketAddress: {
'Fn::Join': ['', [
{ 'Fn::GetAtt': ['Databasereader13B43287', 'Endpoint.Address'] },
':',
{ 'Fn::GetAtt': ['DatabaseB269D8BB', 'Endpoint.Port'] },
]],
},
}]);
});
});

describe('provisioned writer with serverless readers', () => {
test('serverless reader in promotion tier 2 throws warning', () => {
// GIVEN
Expand Down
Loading