Reference
Quick-reference page for the Terraform
HashiCorp Terraform — infrastructure-as-code tool used to provision all AWS resources in this demo. -provisioned S3 Vectors
Amazon S3 Vectors — a purpose-built vector storage capability within S3 that enables similarity search over embeddings without a separate vector database. RAG demo. Use this as a lookup for repository structure, configuration variables, deployment outputs, API routes, and external documentation.
Source repository
Section titled “Source repository”terraform-aws-s3-vectors-rag-demo
Repository layout
Section titled “Repository layout”terraform-aws-s3-vectors-rag-demo/├── main.tf # Provider config, locals├── variables.tf # Input variables├── outputs.tf # Terraform outputs├── s3.tf # S3 bucket for documents├── s3_vectors.tf # S3 Vectors bucket + index├── lambda_ingest.tf # Ingest Lambda + role + policy├── lambda_query.tf # Query Lambda + role + policy├── api_gateway.tf # HTTP API + routes + authorizer├── cognito.tf # User pool, client, groups, admin user├── amplify.tf # Amplify app + branch├── eventbridge.tf # Scheduled ingest trigger├── deploy.tf # Web UI deployment null_resource├── rag/ # Python Lambda code│ ├── fetch.py # RSS fetching + HTML stripping│ ├── ingest.py # Embedding + PutVectors│ ├── query.py # Search + rerank + LLM│ └── config.py # Shared configuration├── web/ # SPA frontend│ ├── index.html│ ├── app.js│ ├── styles.css│ └── config.template.js├── scripts/│ └── deploy-web.sh # Amplify deployment script├── terraform.tfvars.example # Example variables└── README.md # Setup instructions| Path | Purpose |
|---|---|
main.tf | AWS provider configuration, random prefix, and local values |
variables.tf | All input variables with types, defaults, and validations |
outputs.tf | Stack outputs exposed after |
s3.tf | Standard S3 bucket for raw RSS document storage |
s3_vectors.tf | Vector bucket |
lambda_ingest.tf | Ingest Lambda |
lambda_query.tf | Query Lambda function, IAM role, and least-privilege policy |
api_gateway.tf | API Gateway |
cognito.tf | Cognito |
amplify.tf | Amplify |
eventbridge.tf | EventBridge |
deploy.tf |
|
rag/ | Python source for both Lambda functions (shared library) |
web/ | Static SPA frontend served by Amplify |
scripts/ | Helper scripts for deployment automation |
Terraform input variables
Section titled “Terraform input variables”| Name | Type | Required | Description |
|---|---|---|---|
aws_region | string | No (default: | AWS region for all resources |
project_name | string | No (default: | Name prefix for all resources |
vector_bucket_name | string | No (default: | Suffix for the S3 Vectors bucket name |
vector_index_name | string | No (default: | Name of the vector index |
vector_dimension | number | No (default: | Dimensionality of embedding vectors (1–4096) |
vector_distance_metric | string | No (default: | Distance metric: |
embedding_model_id | string | No (default: | Embedding model |
inference_profile_id | string | No (default: | Inference profile |
rss_feed_urls | list(string) | No | List of RSS feed URLs to ingest for the corpus |
admin_email | string | Yes | Email for the default Cognito admin user |
admin_username | string | No (default: | Username for the default admin account |
schedule_expression | string | No (default: | EventBridge schedule for automatic ingest |
Terraform outputs
Section titled “Terraform outputs”| Output | Description | Usage |
|---|---|---|
app_url | Amplify HTTPS URL for the web UI | Open in browser to access the briefing app |
api_endpoint | API Gateway base URL | Base URL for API calls ( |
cognito_user_pool_id | Cognito user pool identifier | Used for authentication configuration |
cognito_client_id | SPA client ID for the Cognito app client | Passed to the web app for login flows |
vector_bucket_name | S3 Vectors bucket name (with random prefix) | Used in Lambda environment and debugging |
ingest_function_name | Ingest Lambda function name | Manual invocation via AWS CLI |
API endpoints
Section titled “API endpoints”The API Gateway
Amazon API Gateway — a managed HTTP API service with JWT authorization, CORS, and throttling. Routes requests to the Query Lambda. exposes three routes, all protected by a Cognito JWT authorizer:
| Method | Path | Description | Lambda |
|---|---|---|---|
POST | /query | Submit a question for RAG | Query Lambda |
POST | /ingest | Trigger a manual corpus ingest from RSS feeds | Ingest Lambda |
GET | /status | Health check — returns ingest stats and index metadata | Query Lambda |
Lambda function details
Section titled “Lambda function details”| Property | Ingest Lambda | Query Lambda |
|---|---|---|
| Runtime | python3.12 | python3.12 |
| Memory | 512 MB | 512 MB |
| Timeout | 300 s | 60 s |
| Handler | ingest.handler | query.handler |
| Source | rag/ingest.py | rag/query.py |
| Trigger | EventBridge schedule, API Gateway, manual invoke | API Gateway only |
Environment variables
Section titled “Environment variables”Both Lambda
AWS Lambda — serverless compute. This project uses two functions: ingest (RSS → embed → store) and query (search → answer). functions receive configuration via environment variables set in Terraform:
| Variable | Function | Description |
|---|---|---|
VECTOR_BUCKET_NAME | Both | S3 Vectors bucket name for API calls |
VECTOR_INDEX_NAME | Both | Vector index name within the bucket |
EMBEDDING_MODEL_ID | Both | Titan V2 |
INFERENCE_PROFILE_ID | Query | Inference profile |
DOCUMENT_BUCKET_NAME | Ingest | S3 bucket for storing raw fetched documents |
RSS_FEED_URLS | Ingest | Comma-separated list of RSS feed URLs to fetch |
Architecture decisions
Section titled “Architecture decisions”Key design choices made in the source repository:
- S3 Vectors over dedicated vector DB — eliminates operational overhead for a demo-scale workload; native S3 integration simplifies IAM
- Single-chunk embedding — each RSS article is embedded as one vector (no chunking) because articles are short enough to fit within the Titan V2 token limit
- Cosine distance metric — chosen for normalized text embeddings where direction matters more than magnitude
- Composite scoring (0.8 similarity + 0.2 recency) — balances relevance with freshness so recent announcements surface even if slightly less similar
- Cross-region inference profile
A Bedrock cross-region inference profile that routes requests to the nearest available region. Used for the LLM (au.anthropic.claude-sonnet-4-5-20250929-v1:0). — avoids single-region capacity limits for the LLM by routing to the nearest available region - EventBridge daily schedule — keeps the corpus fresh without manual intervention; manual trigger available via API for immediate updates
- Cognito JWT authorizer — secures the API without custom auth code; group-based access control via Cognito groups
- Amplify static hosting — zero-config HTTPS hosting with automatic deployments triggered by Terraform
External links
Section titled “External links”AWS documentation
Section titled “AWS documentation”- Amazon S3 Vectors documentation
- Amazon Bedrock documentation
- Amazon Bedrock model access
- Amazon Titan Embeddings V2
- Amazon Cognito developer guide
- AWS Lambda developer guide
Terraform provider
Section titled “Terraform provider”- Terraform AWS Provider — s3vectors_vector_bucket
- Terraform AWS Provider — s3vectors_index
- Terraform AWS Provider changelog