Streamlit Cloud Deployment Guide
This guide explains how to deploy the FRED ML frontend to Streamlit Cloud.
Prerequisites
- GitHub Account: Your code must be in a GitHub repository
- Streamlit Cloud Account: Sign up at streamlit.io/cloud
- AWS Credentials: Configured for S3 and Lambda access
Step 1: Prepare Your Repository
Repository Structure
Ensure your repository has the following structure:
FRED_ML/
βββ frontend/
β βββ app.py
β βββ .streamlit/
β βββ config.toml
βββ requirements.txt
βββ README.md
Update requirements.txt
Make sure your requirements.txt
includes Streamlit dependencies:
streamlit==1.28.1
plotly==5.17.0
altair==5.1.2
boto3==1.34.0
pandas==2.1.4
numpy==1.24.3
Step 2: Configure Streamlit App
Main App File
Your frontend/app.py
should be the main entry point. Streamlit Cloud will automatically detect and run this file.
Streamlit Configuration
The .streamlit/config.toml
file should be configured for production:
[global]
developmentMode = false
[server]
headless = true
port = 8501
enableCORS = false
enableXsrfProtection = false
[browser]
gatherUsageStats = false
Step 3: Deploy to Streamlit Cloud
1. Connect Repository
- Go to share.streamlit.io
- Sign in with your GitHub account
- Click "New app"
- Select your repository
- Set the main file path to
frontend/app.py
2. Configure Environment Variables
In the Streamlit Cloud dashboard, add these environment variables:
# AWS Configuration
AWS_ACCESS_KEY_ID=your_aws_access_key
AWS_SECRET_ACCESS_KEY=your_aws_secret_key
AWS_DEFAULT_REGION=us-west-2
# Application Configuration
S3_BUCKET=fredmlv1
LAMBDA_FUNCTION=fred-ml-processor
3. Advanced Settings
- Python version: 3.9 or higher
- Dependencies: Use
requirements.txt
from root directory - Main file path:
frontend/app.py
Step 4: Environment Variables Setup
AWS Credentials
Create an IAM user with minimal permissions:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::fredmlv1",
"arn:aws:s3:::fredmlv1/*"
]
},
{
"Effect": "Allow",
"Action": [
"lambda:InvokeFunction"
],
"Resource": "arn:aws:lambda:us-east-1:*:function:fred-ml-processor"
}
]
}
Application Variables
Variable | Description | Example |
---|---|---|
S3_BUCKET |
S3 bucket name | fredmlv1 |
LAMBDA_FUNCTION |
Lambda function name | fred-ml-processor |
AWS_ACCESS_KEY_ID |
AWS access key | AKIA... |
AWS_SECRET_ACCESS_KEY |
AWS secret key | ... |
AWS_DEFAULT_REGION |
AWS region | us-east-1 |
Step 5: Deploy and Test
1. Deploy
- Click "Deploy" in Streamlit Cloud
- Wait for the build to complete
- Check the deployment logs for any errors
2. Test the Application
- Open the provided Streamlit URL
- Navigate to the "Analysis" page
- Select indicators and run a test analysis
- Check the "Reports" page for results
3. Monitor Logs
- Check Streamlit Cloud logs for frontend issues
- Monitor AWS CloudWatch logs for Lambda function issues
- Verify S3 bucket for generated reports
Troubleshooting
Common Issues
1. Import Errors
Problem: Module not found errors
Solution: Ensure all dependencies are in requirements.txt
2. AWS Credentials
Problem: Access denied errors Solution: Verify IAM permissions and credentials
3. S3 Access
Problem: Cannot access S3 bucket Solution: Check bucket name and IAM permissions
4. Lambda Invocation
Problem: Lambda function not responding Solution: Verify function name and permissions
Debug Commands
# Test AWS credentials
aws sts get-caller-identity
# Test S3 access
aws s3 ls s3://fredmlv1/
# Test Lambda function
aws lambda invoke --function-name fred-ml-processor --payload '{}' response.json
Production Considerations
Security
- Use IAM Roles: Instead of access keys when possible
- Rotate Credentials: Regularly update AWS credentials
- Monitor Access: Use CloudTrail to monitor API calls
Performance
- Caching: Use Streamlit caching for expensive operations
- Connection Pooling: Reuse AWS connections
- Error Handling: Implement proper error handling
Monitoring
- Streamlit Cloud Metrics: Monitor app performance
- AWS CloudWatch: Monitor Lambda and S3 usage
- Custom Alerts: Set up alerts for failures
Custom Domain (Optional)
If you want to use a custom domain:
- Domain Setup: Configure your domain in Streamlit Cloud
- SSL Certificate: Streamlit Cloud handles SSL automatically
- DNS Configuration: Update your DNS records
Cost Optimization
Streamlit Cloud
- Free Tier: 1 app, limited usage
- Team Plan: Multiple apps, more resources
- Enterprise: Custom pricing
AWS Costs
- Lambda: Pay per invocation
- S3: Pay per storage and requests
- EventBridge: Minimal cost for scheduling
Support
Streamlit Cloud Support
- Documentation: docs.streamlit.io
- Community: discuss.streamlit.io
- GitHub: github.com/streamlit/streamlit
AWS Support
- Documentation: docs.aws.amazon.com
- Support Center: aws.amazon.com/support
Next Steps: After deployment, test the complete workflow and monitor for any issues.