Skip to content
Merged
Changes from all 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
35 changes: 21 additions & 14 deletions agent-blueprint/chatbot-deployment/infrastructure/scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,30 @@ if [ "$ENABLE_COGNITO" = "true" ]; then

# Check if Cognito User Pool already exists but stack does not
# (stack exists = CDK manages the pool normally; stack gone + pool retained = import mode)
echo " Checking for existing Cognito User Pool..."
COGNITO_STACK_EXISTS=$(aws cloudformation describe-stacks --stack-name CognitoAuthStack \
--region $AWS_REGION 2>/dev/null && echo "true" || echo "false")
if [ "$COGNITO_STACK_EXISTS" = "false" ]; then
EXISTING_POOL_ID=$(aws cognito-idp list-user-pools --max-results 60 --region $AWS_REGION \
--query "UserPools[?Name=='chatbot-users'].Id" --output text 2>/dev/null || echo "")
if [ -n "$EXISTING_POOL_ID" ] && [ "$EXISTING_POOL_ID" != "None" ]; then
echo " Retained Cognito User Pool found: $EXISTING_POOL_ID - will import"
export USE_EXISTING_COGNITO=true
export EXISTING_COGNITO_USER_POOL_ID="$EXISTING_POOL_ID"
if [ "$USE_EXISTING_COGNITO" = "true" ] && [ -n "$EXISTING_COGNITO_USER_POOL_ID" ]; then
echo "Using existing Cognito User Pool from configuration: $EXISTING_COGNITO_USER_POOL_ID"
else
echo "Checking for existing Cognito User Pool..."

COGNITO_STACK_EXISTS=$(aws cloudformation describe-stacks --stack-name CognitoAuthStack \
--region $AWS_REGION 2>/dev/null && echo "true" || echo "false")

if [ "$COGNITO_STACK_EXISTS" = "false" ]; then
EXISTING_POOL_ID=$(aws cognito-idp list-user-pools --max-results 60 --region $AWS_REGION \
--query "UserPools[?Name=='chatbot-users'].Id" --output text 2>/dev/null || echo "")

if [ -n "$EXISTING_POOL_ID" ] && [ "$EXISTING_POOL_ID" != "None" ]; then
echo "Retained Cognito User Pool found: $EXISTING_POOL_ID - will import"
export USE_EXISTING_COGNITO=true
export EXISTING_COGNITO_USER_POOL_ID="$EXISTING_POOL_ID"
else
echo "No existing Cognito User Pool found - will create new one"
export USE_EXISTING_COGNITO=false
fi
else
echo " No existing Cognito User Pool found - will create new one"
echo "CognitoAuthStack already exists - CDK will manage the existing pool"
export USE_EXISTING_COGNITO=false
fi
else
echo " CognitoAuthStack already exists - CDK will manage the existing pool"
export USE_EXISTING_COGNITO=false
fi

npx cdk deploy CognitoAuthStack --require-approval never
Expand Down