For an easy to deploy, feature rich, lower latency, lower cost experience, use the original Docker based project. This is meant to be a learning project on AWS services and Rust.
A serverless re-implementation of DocuRAG on AWS, utilizing S3Vector for low cost Retrieval Augmentated Generation implementation.
Behaviours and features differs to original container server implementation due to consideration on request cost and architectural differences.
Include persistent file management and integrated PDF viewer parralleling original implementation.
- Query constraint 🔎
- Users specify a specific machine relevant to their questions. With only relevant documents used in respond.
- Document management 📂
- Documents and their embeddings are stored persistently on S3. Embeds are generated once per file and stored in a S3Vector bucket, reused for any future query.
- Background processing 🖥
- Embeddings for documents are generated in the background after document upload via Lambda triggered from S3 Notifications.
| Query | Documents |
|---|---|
![]() |
![]() |
Refer to AWS CLI Documentation on installing AWS CLI.
Follow AWS IAM Documnetation. Create an AWS IAM Group with the "AdministratorAccess" attached. Create an AWS IAM User which is part of the IAM Group. Note down the access key and secret key.
Run aws configure on your development machine. Enter access key and secret key, along with region and set default output to json.
Keep note of access key and secret key for when setting up Terraform for frontend and backend.
Refer to Terraform Documentation to install Terraform CLI.
Refer to OpenAI Documentation to create an OpenAI API key.
Keep note of the key to set up Terraform for backend.
Create a Personal access tokens (classic) with admin:repo_hook and repo permissions for AWS Amplify deployment and note down for frontend setup.
It is strongly recommended to migrate to Amplify's Github App for fine-grain control, but this was not explored in this project.
Define Terraform secrets in new file <repo>/backend/terraform/secret.tfvars including the following line:
aws_access_key = "YOUR AWS ACCESS KEY"
aws_secret_key = "YOUR AWS SECRET KEY"
openai_api_key = "YOUR OPENAI SERVICE KEY"
Give execution permission to S3Vector creation/deletion scripts (required as S3Vector is not GA hence not yet supported by Terraform). Run the following commands:
chmod +x <repo>/backend/manual/create-vector-bucket.sh
chmod +x <repo>/backend/manual/delete-vector-bucket.sh
Install Rust and upgrade toolchain to version 1.9.0 or higher.
Follow Rust Documentation to install rust, then use rustup to upgrade toolchain if needed.
Install cargo-lambda with the following command:
pip3 install cargo-lambda
Define Terraform secrets in new file <repo>/frontend/secret.tfvars including the following line:
aws_access_key = "YOUR AWS ACCESS KEY"
aws_secret_key = "YOUR AWS SECRET KEY"
github_pat = "YOUR GITHUB PAT"
github_repository = "THE URL OF YOUR GITHUB REPO WHERE AMPLIFY CAN FETCH AND BUILD FROM, SUCH AS https://github.com/someone-s/docurag-cloud"
Once Backend is deployed, find your API Gateway URLs via the AWS Console.
For docurag-api-gateway, which is a REST API Gateway, follow this AWS REST API Gateway Documentation, note down the Invoke URL of the deployed stage.
For docurag-websocket-gateway, which is a Websocket API Gateway, refer to the AWS REST API Gateway Documentation but look for Websocket URL instead of the Invoke URL.
create .env.development.local in <repo>/frontend/source for when npm run dev in <repo>/frontend/source. Include the following content:
VITE_TESTING_API_BASE_PATH = 'Beginning with https:// your AWS REST API Gateway Invoke URL'
VITE_TESTING_API_QUERY_WS_PATH = 'Beginning with wss:// your AWS Websocket API Gateway Websocket URL'
For simplicity, we will only the same API Gateway deployment stage for development and production.
modify .env.production in <repo>/frontend/source with your own deployed API GATEWAY for deployment with amplify. Include the following content:
VITE_PRODUCTION_API_BASE_PATH = 'Beginning with https:// your AWS REST API Gateway Invoke URL'
VITE_PRODUCTION_API_QUERY_WS_PATH = 'Beginning with wss:// your AWS Websocket API Gateway Websocket URL'
Source for each of the Lambda functions can be found in <repo>/backend/source/<lambda function directory>
Run the following command for each of the Lambda function.
cd <repo>/backend/source/<lambda function directory>
cargo lambda build --release --arm64 --output-format zip
Changes in Lambda builds are picked up by Terraform automatically.
Amplify handles the building of the frontend in the cloud.
Create S3Vectors in us-east-1 as it is not globally or generally available yet. Run the following command:
<repo>/backend/manual/create-vector-bucket.sh
Deploy backend with terraform. Run the following command in <repo>/backend/terraform:
terraform init
terraform apply -var-file secret.tfvars
Ensure changes to the Repo are pushed to the origin (GitHub) before proceeding as Amplify will build from origin.
Deploy frontend with terraform. Run the following command in <repo>/frontend:
terraform init
terraform apply --var-file secret.tfvars


