Summary
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 providing:
- USE_EXISTING_COGNITO=true
- EXISTING_COGNITO_USER_POOL_ID=
the script overrides this configuration and creates a new Cognito User Pool instead of reusing the existing one.
Steps to Reproduce
-
First deployment (no env variables):
- Run deployment without USE_EXISTING_COGNITO
- A new Cognito User Pool is created successfully
-
Second deployment (reuse existing pool):
- Set:
export USE_EXISTING_COGNITO=true
export EXISTING_COGNITO_USER_POOL_ID=
- Run deployment again
-
Observe behavior:
- Script resets USE_EXISTING_COGNITO=false
- A new Cognito User Pool is created again
Expected Behavior
When both variables are provided:
- USE_EXISTING_COGNITO=true
- EXISTING_COGNITO_USER_POOL_ID is valid
the script should:
- Reuse the existing Cognito User Pool
- Skip auto-detection and creation logic
Current Behavior
The script checks stack existence and overrides:
- USE_EXISTING_COGNITO=false
even when the user has explicitly provided configuration.
Impact
- Prevents reuse of existing Cognito resources
- Leads to unnecessary creation of multiple User Pools
- Breaks expected idempotent deployment behavior
Proposed Fix
Update logic to:
- Respect user-provided configuration when both variables are set
- Avoid overriding USE_EXISTING_COGNITO in that case
- Only run auto-detection when configuration is not provided
Summary
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 providing:
the script overrides this configuration and creates a new Cognito User Pool instead of reusing the existing one.
Steps to Reproduce
First deployment (no env variables):
Second deployment (reuse existing pool):
export USE_EXISTING_COGNITO=true
export EXISTING_COGNITO_USER_POOL_ID=
Observe behavior:
Expected Behavior
When both variables are provided:
the script should:
Current Behavior
The script checks stack existence and overrides:
even when the user has explicitly provided configuration.
Impact
Proposed Fix
Update logic to: