Skip to content

fix: respect existing Cognito configuration during redeploy#42

Open
amitkumawat-node wants to merge 1 commit intoaws-samples:mainfrom
amitkumawat-node:fix/cognito-env-override
Open

fix: respect existing Cognito configuration during redeploy#42
amitkumawat-node wants to merge 1 commit intoaws-samples:mainfrom
amitkumawat-node:fix/cognito-env-override

Conversation

@amitkumawat-node
Copy link
Copy Markdown
Contributor

Summary

This PR fixes an issue where user-provided Cognito configuration is ignored during redeployments, causing a new User Pool to be created instead of reusing an existing one.

Problem

On initial deployment, a new Cognito User Pool is created as expected when no environment variables are provided.

However, on subsequent deployments, even when explicitly setting:

  • USE_EXISTING_COGNITO=true
  • EXISTING_COGNITO_USER_POOL_ID=

the script overrides this configuration based on stack detection logic and sets USE_EXISTING_COGNITO=false. As a result, a new Cognito User Pool is created on every run.

Root Cause

The deployment script prioritizes auto-detection logic over user-provided environment variables, leading to unintended overrides.

Changes

  • Updated logic to check for user-provided configuration first
  • Use existing Cognito User Pool when both:
    • USE_EXISTING_COGNITO=true
    • EXISTING_COGNITO_USER_POOL_ID is provided
  • Fallback to existing auto-detection logic when configuration is not provided
  • Preserved existing behavior for first-time deployments

Behavior After Fix

  • First deployment (no env variables): creates a new User Pool
  • Subsequent deployment with env variables: reuses existing User Pool
  • Default auto-detection flow remains unchanged

Impact

  • Prevents unnecessary creation of multiple Cognito User Pools
  • Ensures idempotent deployments
  • Improves predictability and user control

Testing

  • Verified initial deployment creates a new Cognito User Pool
  • Verified redeployment with env variables reuses the existing pool
  • Verified fallback behavior when env variables are not provided

Related Issue

Fixes #41

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.

Cognito configuration ignored on redeploy when using existing User Pool

1 participant