Skip to content

Conversation

@vigneshrajsb
Copy link
Contributor

Summary

Fixes duplicate database creation errors during static environment redeployment by checking AWS for existing RDS instances before attempting to create them.

Problem

When redeploying a static environment, the Aurora restore deploy (npc-db) attempts to recreate an already-existing RDS database, causing an error. This happens because:

  1. DeploymentManager resets all deploy statuses to QUEUED before deployment
  2. The status check in deployAurora() fails
  3. cli.cliDeploy() tries to recreate the existing database

Solution

Added a pre-flight check in deployAurora() that queries AWS to verify if the RDS database already exists before attempting to create it.

Changes

  • New helper function: findExistingAuroraDatabase(buildUuid, serviceName) - Generic, reusable function that queries AWS for existing RDS instances by tags
  • Pre-flight check: Before calling cli.cliDeploy(), check if database exists in AWS. If found, skip creation and use existing endpoint
  • Refactored post-creation lookup: Replaced duplicate AWS query code with helper function call

Benefits

  • Idempotent: Safe to call multiple times
  • Defensive: Works regardless of deploy status state
  • Generic: Helper function decoupled from Deploy model for reusability
  • Maintainable: Single source of truth for database lookup logic
  • No breaking changes: Backward compatible with existing behavior

Test Plan

  1. Deploy a static environment with Aurora restore
  2. Redeploy the same environment
  3. Verify that Aurora restore skips creation and uses existing database endpoint

Prevents duplicate database creation errors during redeployment by
checking AWS for existing RDS instances before attempting to create.

- Extract AWS RDS lookup logic into generic helper function
- Add pre-flight check in deployAurora() before cli.cliDeploy()
- Refactor post-creation lookup to use new helper function

This makes Aurora restore operations idempotent and safe to retry.
@vigneshrajsb vigneshrajsb requested a review from a team as a code owner November 3, 2025 22:35
@vigneshrajsb vigneshrajsb merged commit 288192a into main Nov 3, 2025
1 check passed
vigneshrajsb added a commit to nickh8/lifecycle that referenced this pull request Nov 3, 2025
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants