AWS Bedrock-powered document querying system with Aurora PostgreSQL vector database.
project-root/
│
├── stack1/ # VPC, Aurora Serverless, S3
│ ├── main.tf
│ ├── outputs.tf
│ └── variables.tf
│
├── stack2/ # Bedrock Knowledge Base
│ ├── main.tf
│ ├── outputs.tf
│ └── variables.tf
│
├── modules/
│ ├── vpc/
│ ├── aurora_serverless/
│ ├── s3/
│ └── bedrock_kb/
│
├── scripts/
│ ├── aurora_sql.sql
│ └── upload_to_s3.py
│
├── spec-sheets/ # Place your PDF files here
│
├── python/ # Complete Python utilities
│ ├── bedrock_utils.py
│ ├── lambda_function.py
│ ├── requirements.txt
│ └── test_valid_prompt.py
│
└── README.md
- Modular Terraform Architecture: Separated into reusable modules
- Two-Stack Deployment: Infrastructure and Bedrock components
- Aurora PostgreSQL Serverless: Vector database with pgvector
- S3 Document Storage: Secure document repository
- Bedrock Knowledge Base: AI-powered document querying
- Enhanced Python Utilities: Complete with validation and error handling
-
Navigate to Stack 1 (VPC, Aurora, S3):
cd stack1 -
Initialize Terraform:
terraform init
-
Review and modify variables in
variables.tfas needed:- AWS region
- VPC CIDR block
- Aurora Serverless configuration
- S3 bucket settings
-
Deploy the infrastructure:
terraform apply
Review the planned changes and type "yes" to confirm.
-
Note the outputs, particularly:
- Aurora cluster ARN
- Aurora cluster endpoint
- S3 bucket ARN
- RDS secret ARN
-
Run the SQL setup script using Aurora Query Editor or psql:
# Use the SQL commands in scripts/aurora_sql.sql -
Update the bedrock user password in the script with the actual password from Secrets Manager:
aws secretsmanager get-secret-value --secret-id [bedrock-user-secret] --region us-east-1
-
Navigate to Stack 2:
cd ../stack2 -
Initialize Terraform:
terraform init
-
Update variables in
variables.tfwith outputs from Stack 1:aurora_cluster_arndocuments_bucket_arnrds_secret_arn
-
Deploy the Bedrock components:
terraform apply
-
Place your PDF files in the
spec-sheets/folder -
Update the S3 upload script with your bucket name:
# Edit scripts/upload_to_s3.py bucket_name = "your-bucket-name-here"
-
Upload documents to S3:
python scripts/upload_to_s3.py
-
Sync the Knowledge Base:
- Go to AWS Console → Bedrock → Knowledge Bases
- Find your knowledge base → Data sources
- Click "Sync" to process uploaded documents
The enhanced Python utilities include:
query_knowledge_base(query, kb_id): Query with error handlinggenerate_response(prompt, model_id, temperature, top_p, max_tokens): Generate responses with validationvalid_prompt(prompt, model_id): AI-powered prompt classification
cd python
python3 test_valid_prompt.py- Permissions issues: Ensure AWS credentials have necessary permissions
- Database connection: Check security group allows port 5432 access
- S3 upload failures: Verify write permissions to S3 bucket
- Terraform errors: Ensure compatible version and correct module sources
- Bedrock access: Ensure models are enabled in Bedrock console
- Aurora Serverless scales to zero when not in use
- Use
terraform destroywhen not actively testing - Monitor usage in AWS Cost Explorer
- Consider using smaller instance types for development