This project implements an AI-powered LangChain agent that dynamically generates AWS S3 Presigned URLs (GET or PUT) based on natural language input. The agent is wrapped in a FastAPI server and supports integration into secure backend workflows.
π§ What It Does
- Accepts input like:
Generate download link bucket=my-bucket key=path/to/file.txt - Uses LangChain tools to interpret commands
- Generates a presigned URL via
boto3 - Responds with a secure, time-limited URL (GET/PUT)
π§± Tech Stack
- π§ LangChain
- π AWS S3 + Boto3
- β‘ FastAPI
- π³ Docker-ready
π Folder Structure
langchain_s3_agent/
βββ main.py # FastAPI app
βββ agent.py # LangChain agent logic
βββ aws_utils.py # Presigned URL generator
βββ .env # AWS credentials (not committed)
βββ requirements.txt
βββ Dockerfile (optional)
π Quick Start
1οΈβ£ Clone and Install
git clone https://github.com/your-repo/langchain-s3-agent.git
cd langchain-s3-agent
pip install -r requirements.txt
2οΈβ£ Add AWS Credentials to .env
env
AWS_ACCESS_KEY_ID=your_key
AWS_SECRET_ACCESS_KEY=your_secret
AWS_REGION=us-east-1
3οΈβ£ Run the API
uvicorn main:app --reload
π‘ How to Use
POST /query
Request Body:
{
"query": "Generate download link bucket=my-bucket key=path/to/file.txt"
}
Response:
{
"response": "GET URL for `path/to/file.txt`: https://s3.amazonaws.com/..."
}
π§ Supported Prompts
Action Prompt Format Example
Download Generate download link bucket=my-bucket key=folder/file.txt
Upload Generate upload link bucket=my-bucket key=uploads/newfile.txt
π§ͺ Example CURL Test
curl -X POST http://localhost:8000/query \
-H "Content-Type: application/json" \
-d '{"query": "Generate upload link bucket=my-bucket key=upload/test.txt"}'
π³ Optional: Docker Support
Dockerfile
dockerfile
FROM python:3.11
WORKDIR /app
COPY . .
RUN pip install -r requirements.txt
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
Build & Run
docker build -t s3-agent .
docker run -p 8000:8000 --env-file .env s3-agent
π IAM Policy Required
Your AWS IAM user or role must have:
{
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:PutObject"],
"Resource": "arn:aws:s3:::your-bucket-name/*"
}
π Roadmap Ideas
Add expiration input (expires_in=600)
Enable presigned POST for HTML form uploads
Add token auth to protect the API
Web UI with React or Streamlit
π Resources
AWS S3 Presigned URLs
Boto3 Docs
LangChain Docs
FastAPI Docs
Top comments (2)
Absolutely brilliant ideaβturning presigned URL generation into a natural language task is next-level productivity!
Very intelligent