A Python project for generating and using S3 presigned URLs with a chat interface.
Project description
ai-chat
A Python project for generating and using S3 presigned URLs with a chat interface powered by AWS Bedrock and Claude. This project includes:
- S3 presigned URL generation for secure upload/download operations
- File upload/download using presigned URLs
- MCP (Model Context Protocol) server for tool integration
- Chat client that interacts with Claude via LiteLLM and AWS Bedrock
- AWS integration for both S3 operations and AI model access
Features
- Generate presigned URLs for S3 bucket operations
- Upload and download files securely using presigned URLs
- Interactive chat interface with AI assistance
- Tool calling capabilities through MCP protocol
- Support for both direct Anthropic API and AWS Bedrock
Requirements
- Python 3.12+
- AWS account with appropriate permissions for:
- S3 bucket access
- AWS Bedrock model access (for Claude models)
- AWS credentials configured
Installation
Using pip with requirements.txt:
pip install -r requirements.txt
Using pyproject.toml:
pip install .
Configuration
Environment Variables
Create a .env file in the project root with the following variables:
# AWS Credentials for S3 and Bedrock
AWS_ACCESS_KEY_ID=your-aws-access-key-id
AWS_SECRET_ACCESS_KEY=your-aws-secret-access-key
AWS_SESSION_TOKEN=your-aws-session-token # Optional for temporary credentials
AWS_DEFAULT_REGION=us-east-1
# LiteLLM Configuration for AWS Bedrock
LITELLM_LOG=INFO
AWS_REGION_NAME=us-east-1
# Optional: Anthropic API Key (if using direct API instead of Bedrock)
ANTHROPIC_API_KEY=your-anthropic-api-key
AWS Permissions
Ensure your AWS credentials have the following permissions:
For S3 operations:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:PutObject",
"s3:GeneratePresignedUrl"
],
"Resource": "arn:aws:s3:::your-bucket-name/*"
}
]
}
For AWS Bedrock:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"bedrock:InvokeModel"
],
"Resource": "arn:aws:bedrock:*::foundation-model/anthropic.claude-*"
}
]
}
Usage
1. Start the MCP Server
The presigned_url.py script can function as both a library and an MCP server:
python presigned_url.py --mcp-server
2. Run the Chat Client
Start the interactive chat client that connects to the MCP server:
python client.py presigned_url.py --mcp-server
3. Using the Tools
Once the chat client is running, you can use natural language to:
- Generate presigned URLs: "Create a presigned URL for uploading to bucket 'my-bucket' with key 'file.txt'"
- Upload files: "Upload 'local-file.txt' to the presigned URL"
- Download files: "Download from the presigned URL and save as 'downloaded-file.txt'"
Model Configuration
Using AWS Bedrock (Recommended)
To use Claude models through AWS Bedrock, update the model name in client.py:
# Replace this line in client.py
model="claude-3-5-sonnet-20241022"
# With this for Bedrock
model="bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0"
Using Direct Anthropic API
If you prefer to use the direct Anthropic API, ensure you have set the ANTHROPIC_API_KEY in your .env file and use the standard model names.
Project Structure
ai-chat/
├── client.py # Interactive chat client
├── presigned_url.py # Merged S3 utilities and MCP server
├── app.py # Additional application logic
├── requirements.txt # Python dependencies
├── pyproject.toml # Project configuration
├── .env # Environment variables (create this)
└── README.md # This file
Troubleshooting
Common Issues
-
AWS Credentials Error: Ensure your AWS credentials are correctly set in the
.envfile and have the necessary permissions. -
Bedrock Access Denied: Make sure you have enabled the Claude models in your AWS Bedrock console and have the appropriate IAM permissions.
-
S3 Bucket Access: Verify that your AWS credentials have access to the S3 bucket you're trying to use.
-
Region Mismatch: Ensure the AWS region in your
.envfile matches where your resources are located.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cli_chatbot-0.1.1.tar.gz.
File metadata
- Download URL: cli_chatbot-0.1.1.tar.gz
- Upload date:
- Size: 93.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc4d4deeccef6f7513b52d51c2969fd0f15a7c1a1b66d1412380582bf50f64ae
|
|
| MD5 |
d92dfb0619e96c2aa45d2e5b4027c502
|
|
| BLAKE2b-256 |
a20cdc1f16166ddee9fe96e7d11e027a8925e25fa80f9b20cccc85f83d4a55dc
|
File details
Details for the file cli_chatbot-0.1.1-py3-none-any.whl.
File metadata
- Download URL: cli_chatbot-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7eb229ee6e61d52683029cf71f799c1d23a0981a1952956064c5127bdcaee4ac
|
|
| MD5 |
59a57960efcc6ff91d97040ff46fddae
|
|
| BLAKE2b-256 |
7ba35150986530f02eafcbfc5f95c6f20d3e3d6297861703ecdef97005a7e4ba
|