Use rds cluster endpoint instead of instance endpoint - #50
Conversation
nickh8
commented
Sep 19, 2025
- Update RDS Aurora deployment to use cluster endpoint instead of instance endpoint
- Ensures deployments are resilient to instance failures and replacements
|
hi @nickh8 !! thanks for contributing.. will test for backward compatibility and get back to you!! the changes look good but since |
Thanks @vigneshrajsb! I made some changes to instead attempt to find the cluster endpoint if the instance is part of a cluster. If it is part of a cluster it will use the cluster endpoint. If the instance is not part of a cluster it should continue using the instance endpoint. |
There was a problem hiding this comment.
Pull Request Overview
Switch deployment logic to use the Aurora cluster endpoint instead of a single instance endpoint to improve resilience against instance failovers.
- Extracts DB instance identifier from ARN instead of passing ARN as a filter.
- Adds logic to look up the cluster and prefer the cluster (writer) endpoint over the instance endpoint.
- Updates patch operation to occur only if a resolved databaseAddress is found.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| if (instanceArn) { | ||
| const instanceIdentifier = instanceArn.split(':').pop(); | ||
| if (instanceIdentifier) { | ||
| const instances = await rds | ||
| .describeDBInstances({ | ||
| DBInstanceIdentifier: instanceIdentifier, | ||
| }) | ||
| .promise(); | ||
| const database = instances.DBInstances?.[0]; | ||
| if (database) { | ||
| databaseAddress = database.Endpoint?.Address; | ||
| if (database.DBClusterIdentifier) { | ||
| const clusters = await rds | ||
| .describeDBClusters({ | ||
| DBClusterIdentifier: database.DBClusterIdentifier, | ||
| }) | ||
| .promise(); | ||
| const clusterEndpoint = clusters.DBClusters?.[0]?.Endpoint; | ||
| if (clusterEndpoint) { | ||
| databaseAddress = clusterEndpoint; | ||
| } | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
[nitpick] This block is highly nested (five levels) which reduces readability. Consider flattening with early returns/guards or extracting helper functions (e.g., getInstanceIdentifierFromArn, fetchClusterEndpoint) to clarify the happy path and reduce indentation.
Combines improvements from both PRs: - Pre-flight check for existing Aurora databases (PR GoodRxOSS#63) - Cluster endpoint usage instead of instance endpoint (PR GoodRxOSS#50) The helper function now uses cluster endpoints for better resilience during instance failures and replacements.