Eashan Kaushik 88e19eddc9
customer-support-assistant v1 (#103)
* feat(customer-support): updated code

* Delete 02-use-cases/customer-support-assistant/Dockerfile

Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>

* Update .gitignore

Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>

---------

Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>
2025-07-21 11:34:00 -04:00

96 lines
2.7 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
set -e
set -o pipefail
# ----- Config -----
BUCKET_NAME=${1:-customersupport}
INFRA_STACK_NAME=${2:-CustomerSupportStackInfra}
COGNITO_STACK_NAME=${3:-CustomerSupportStackCognito}
INFRA_TEMPLATE_FILE="prerequisite/infrastructure.yaml"
COGNITO_TEMPLATE_FILE="prerequisite/cognito.yaml"
REGION=$(aws configure get region)
ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
FULL_BUCKET_NAME="${BUCKET_NAME}-${ACCOUNT_ID}"
ZIP_FILE="lambda.zip"
LAMBDA_SRC="prerequisite/lambda/python"
S3_KEY="${ZIP_FILE}"
# ----- 1. Create S3 bucket -----
echo "🪣 Using S3 bucket: $FULL_BUCKET_NAME"
if [ "$REGION" = "us-east-1" ]; then
aws s3api create-bucket \
--bucket "$FULL_BUCKET_NAME" \
2>/dev/null || echo " Bucket may already exist or be owned by you."
else
aws s3api create-bucket \
--bucket "$FULL_BUCKET_NAME" \
--region "$REGION" \
--create-bucket-configuration LocationConstraint="$REGION" \
2>/dev/null || echo " Bucket may already exist or be owned by you."
fi
# ----- 2. Zip Lambda code -----
echo "📦 Zipping contents of $LAMBDA_SRC into $ZIP_FILE..."
cd "$LAMBDA_SRC"
zip -r "../../../$ZIP_FILE" . > /dev/null
cd - > /dev/null
# ----- 3. Upload to S3 -----
echo "☁️ Uploading $ZIP_FILE to s3://$FULL_BUCKET_NAME/$S3_KEY..."
aws s3 cp "$ZIP_FILE" "s3://$FULL_BUCKET_NAME/$S3_KEY"
# ----- 4. Deploy CloudFormation -----
deploy_stack() {
set +e
local stack_name=$1
local template_file=$2
shift 2
local params=("$@")
echo "🚀 Deploying CloudFormation stack: $stack_name"
output=$(aws cloudformation deploy \
--stack-name "$stack_name" \
--template-file "$template_file" \
--capabilities CAPABILITY_NAMED_IAM \
--region "$REGION" \
"${params[@]}" 2>&1)
exit_code=$?
echo "$output"
if [ $exit_code -ne 0 ]; then
if echo "$output" | grep -qi "No changes to deploy"; then
echo " No updates for stack $stack_name, continuing..."
return 0
else
echo "❌ Error deploying stack $stack_name:"
echo "$output"
return $exit_code
fi
else
echo "✅ Stack $stack_name deployed successfully."
return 0
fi
}
# ----- Run both stacks -----
echo "🔧 Starting deployment of infrastructure stack..."
deploy_stack "$INFRA_STACK_NAME" "$INFRA_TEMPLATE_FILE" --parameter-overrides LambdaS3Bucket="$FULL_BUCKET_NAME" LambdaS3Key="$S3_KEY"
infra_exit_code=$?
echo "🔧 Starting deployment of Cognito stack..."
deploy_stack "$COGNITO_STACK_NAME" "$COGNITO_TEMPLATE_FILE"
cognito_exit_code=$?
echo "🔍 Fetching Knowledge Base and Data Source IDs from SSM..."
# ----- 6. Create Knowledge Base -----
python prerequisite/knowledge_base.py --mode create
echo "✅ Deployment complete."