This document explains how to configure the RAG application for local development and AWS deployment.
Create a .env file in the project root with the following variables:
MY_OPENAI_API_KEY=sk-your-openai-api-key-hereHow to obtain:
- Sign up or log in to OpenAI Platform
- Navigate to API Keys
- Create a new secret key
- Copy and paste into your
.envfile
Note: Keep this key secure and never commit it to version control.
AWS_ACCESS_ID=your-aws-access-key-id
AWS_ACCESS_KEY=your-aws-secret-access-key
AWS_REGION=ap-south-1How to obtain:
- Log in to AWS IAM Console
- Create a new IAM user or use an existing one
- Attach policies for:
AmazonS3FullAccess(for document storage)AmazonOpenSearchServiceFullAccess(for vector search)AmazonElastiCacheFullAccess(for caching)
- Generate access keys under "Security credentials"
- Copy the Access Key ID and Secret Access Key
Region: Set to your preferred AWS region (e.g., us-east-1, ap-south-1, eu-west-1)
BUCKET_NAME=your-s3-bucket-nameHow to set up:
- Create an S3 bucket via AWS S3 Console
- Choose a globally unique bucket name
- Select the same region as
AWS_REGION - Use this bucket to store raw document files (PDFs, reports, etc.)
Example: raw-annual-report-docs
OPENSEARCH_HOST=https://your-opensearch-domain.region.es.amazonaws.com
OPENSEARCH_INDEX=rag-docsHow to set up:
- Create an OpenSearch domain via AWS OpenSearch Console
- Note the domain endpoint (e.g.,
https://search-your-domain.region.es.amazonaws.com) - Apply the index mapping from
src/aws_infra/opensearch/index_mapping.jsonvia OpenSearch Dashboards - Set
OPENSEARCH_INDEXto your index name (default:rag-docs)
Security: Ensure your IAM user has access to the OpenSearch domain via access policies.
REDIS_HOST=localhost
REDIS_PORT=6379How to set up:
- Install Redis locally:
- macOS:
brew install redis - Linux:
sudo apt install redis-server - Windows: Use Redis for Windows
- macOS:
- Start Redis:
redis-server - Verify connection:
redis-cli ping(should returnPONG)
ELASTICACHE_ENDPOINT=your-elasticache-endpoint.cache.amazonaws.comHow to set up:
- Create an ElastiCache cluster via AWS ElastiCache Console
- Choose "Redis" as the engine
- Select "Serverless" or "Design your own cache" based on your needs
- Note the primary endpoint (e.g.,
your-cache.serverless.region.cache.amazonaws.com) - Ensure your EC2 instance security group allows inbound connections to ElastiCache
Switching between local and AWS Redis:
- The application detects the environment automatically
- For local development, ensure
REDIS_HOSTandREDIS_PORTare set - For AWS deployment, ensure
ELASTICACHE_ENDPOINTis set
# OpenAI API
MY_OPENAI_API_KEY=sk-proj-abc123...
# AWS Configuration
AWS_ACCESS_ID=AKIAIOSFODNN7EXAMPLE
AWS_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
AWS_REGION=ap-south-1
# S3 Bucket Name
BUCKET_NAME=my-rag-documents
# OpenSearch
OPENSEARCH_HOST=https://search-my-domain.ap-south-1.es.amazonaws.com
OPENSEARCH_INDEX=rag-docs
# Local Redis
REDIS_HOST=localhost
REDIS_PORT=6379
# AWS ElastiCache
ELASTICACHE_ENDPOINT=my-cache.serverless.aps1.cache.amazonaws.com- Never commit
.envto version control (already in.gitignore) - Rotate AWS credentials regularly
- Use IAM roles with least-privilege access
- Enable MFA on your AWS account
- Store production secrets in AWS Secrets Manager or Parameter Store for enhanced security