This directory contains all deployment and management scripts for the RAG System AWS deployment.
scripts/
βββ deploy-full-stack.sh # π Master deployment script (FIRST TIME)
βββ deploy-update-only.sh # π Code update script (SUBSEQUENT DEPLOYMENTS)
βββ cleanup-deployment.sh # π§Ή Cleanup and resource management
βββ database/ # ποΈ Database management
β βββ trigger-db-initializer.sh # βββ Trigger DbInitializer to seed all data
β βββ seed-roles-direct.sh # βββ [LEGACY] Direct seed roles and analytics types
β βββ seed-default-users.sh # βββ [LEGACY] Direct seed default admin/analyst users
βββ deployment/ # π¦ Application deployment
β βββ deploy-lambda.sh # βββ Deploy Lambda function code
β βββ configure-environment.sh # βββ Configure Lambda environment variables
βββ infrastructure/ # ποΈ AWS infrastructure provisioning
β βββ provision-rds.sh # βββ Deploy RDS PostgreSQL database
β βββ provision-lambda.sh # βββ Provision Lambda function infrastructure
β βββ provision-api-gateway.sh # βββ Deploy API Gateway
βββ integration/ # π Integration scripts
βββ migration/ # π Database migrations
β βββ run-migrations.sh # βββ Run Entity Framework migrations
βββ testing/ # π§ͺ Testing and validation scripts
β βββ test-api.sh # βββ Test API endpoints
β βββ test-user-roles.sh # βββ Test authentication and roles
β βββ test-lambda-db-connection.sh # βββ Test Lambda-RDS connectivity
β βββ test-credential-detection.sh # βββ Test AWS credential detection
β βββ run-all-tests.sh # βββ Run all test suites
βββ setup/ # βοΈ Setup and configuration
β βββ setup-deployment.sh # βββ Initial project setup
βββ temp/ # π Temporary files (JSON, build artifacts)
βββ utilities/ # π οΈ Shared utilities
βββ logging.sh # βββ Logging functions
βββ error-handling.sh # βββ Error handling utilities
βββ validate-aws-cli.sh # βββ AWS CLI validation
βββ parse-appsettings.sh # βββ Configuration parsing
Deploy everything with one command:
./deploy-full-stack.shUpdate Lambda code without touching infrastructure or database:
./deploy-update-only.shThis runs the complete deployment pipeline:
- ποΈ Deploy RDS Database
- β‘ Deploy Lambda Function
- π Run Database Migrations (from Lambda to DB)
- π± Trigger DbInitializer (automatically seeds roles, analytics types, and users)
- π Deploy API Gateway
- π§ͺ Run Tests
# Production deployment
./deploy-full-stack.sh --environment production --project-name myrag
# Development without tests
./deploy-full-stack.sh --skip-tests
# Skip database seeding (for existing databases)
./deploy-full-stack.sh --skip-seeding# Deploy RDS database
./infrastructure/provision-rds.sh --environment dev
# Deploy Lambda infrastructure
./infrastructure/provision-lambda.sh --environment dev
# Deploy API Gateway
./infrastructure/provision-api-gateway.sh --environment dev# Deploy Lambda function code
./deployment/deploy-lambda.sh --environment dev
# Configure Lambda environment variables
./deployment/configure-environment.sh --function-name myapp-dev-api# Run Entity Framework migrations
./migration/run-migrations.sh --environment dev
# Trigger DbInitializer to seed all data (roles, analytics types, users)
./database/trigger-db-initializer.sh --function-name myapp-dev-api# Test Lambda-RDS connection
./tests/test-lambda-db-connection.sh
# Test API endpoints
./tests/test-api.sh
# Test user authentication and roles
./tests/test-user-roles.sh
# Test AWS credential detection
./tests/test-credential-detection.sh
# Run all tests
./tests/run-all-tests.sh# Clean temporary files only (default)
./cleanup-deployment.sh
# Clean everything except AWS resources
./cleanup-deployment.sh --all
# Clean specific categories
./cleanup-deployment.sh --clean-logs --clean-temp --clean-checkpoints./cleanup-deployment.sh --destroy-aws --environment devScripts use these environment variables:
ENVIRONMENT=dev # Deployment environment
PROJECT_NAME=myapp # Project identifier
SKIP_TESTS=false # Skip tests during deployment
SKIP_SEEDING=false # Skip database seedingEnsure AWS CLI is configured:
aws configure
# or
export AWS_ACCESS_KEY_ID=your-key
export AWS_SECRET_ACCESS_KEY=your-secret
export AWS_DEFAULT_REGION=ap-southeast-1Note: All other configuration is automatically read from RAG.APIs/appsettings.json. No additional configuration files are needed.
IMPORTANT: Scripts must be run in this specific order for first-time deployment:
- Infrastructure:
provision-rds.shβprovision-lambda.sh - Application:
deploy-lambda.sh - Database:
run-migrations.sh(from Lambda to DB) - Seeding:
trigger-db-initializer.sh(DbInitializer seeds roles, analytics types, users automatically) - Gateway:
provision-api-gateway.sh - Testing:
test-*scripts
The deploy-full-stack.sh script handles this order automatically and is the recommended deployment method.
Scripts create temporary files in:
temp/directory (auto-created)- Root-level JSON files (auto-cleaned)
Deployment logs are stored in:
../logs/- Deployment logs../deployment_logs/- Detailed deployment logs../deployment_checkpoints/- State tracking files
Use cleanup-deployment.sh to manage temporary files and logs.
All scripts use shared utilities from utilities/:
- logging.sh: Colored logging functions (
log_info,log_success,log_error) - error-handling.sh: Error handling and cleanup functions
- validate-aws-cli.sh: AWS CLI validation and setup
- parse-appsettings.sh: Configuration file parsing
All scripts include:
- Automatic error detection (
set -euo pipefail) - Cleanup on exit
- Detailed error messages with remediation steps
- Rollback capabilities where applicable
-
Permission Denied: Ensure scripts are executable
chmod +x scripts/*.sh scripts/*/*.sh
-
AWS Credentials: The scripts support flexible credential detection
Automatic Detection: Scripts automatically detect credentials from:
- AWS CLI configuration (
aws configure) - Environment variables (
AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY) - AWS profiles (
AWS_PROFILE) - IAM roles (EC2/Lambda instance profiles)
- AWS credentials files (
~/.aws/credentials,~/.aws/config)
Verification: Test any credential method with:
aws sts get-caller-identity
No Configuration Required: If you already have AWS credentials set up via any method, you don't need to run
aws configure. - AWS CLI configuration (
-
Dependencies: Check prerequisites
# Required: AWS CLI, .NET SDK, PostgreSQL client aws --version dotnet --version psql --version
Enable verbose logging:
export DEBUG=true
./deploy-full-stack.shCheck deployment logs:
ls -la ../logs/
tail -f ../logs/deployment_*.logBefore running any scripts:
- β AWS CLI v2.0+ installed and configured
- β .NET SDK 8.0+ installed
- β PostgreSQL client (psql) installed
- β Bash shell available
- β AWS permissions for RDS, Lambda, API Gateway, IAM
After successful deployment:
- RDS Database:
{project}-{env}-db(e.g.,myapp-dev-db) - Lambda Function:
{project}-{env}-api(e.g.,myapp-dev-api) - API Gateway: REST API with Swagger documentation
- Default Users:
- Admin:
admin@rag.com/Admin@123!! - Analyst:
analyst@rag.com/Analyst@123!!
- Admin:
For issues:
- Check script logs in
../logs/ - Verify AWS resource status in AWS Console
- Run individual scripts with
--helpfor usage information - Check CloudWatch logs for Lambda function issues
Last Updated: March 2026
Scripts Version: 2.0