A complete end-to-end serverless automation system that generates video ideas, creates realistic AI talking head videos, and automatically posts them to YouTube multiple times per day.
- 🤖 Automated Idea Generation: Uses GPT-4 to generate engaging video ideas based on customizable topics
- 🎥 AI Video Creation: Integrates with HeyGen or D-ID to create realistic talking head videos
- 📺 YouTube Auto-Posting: Automatically uploads videos to YouTube with metadata and scheduling
- ⏰ Configurable Scheduling: Post videos multiple times per day at specified times
- 📊 Status Tracking: Complete visibility into idea generation, video creation, and upload status
- 🔄 Error Handling: Automatic retries and comprehensive error logging
- 🛠️ API Control: REST API for manual triggering and configuration
- ☁️ Serverless: Built on AWS Lambda, DynamoDB, and EventBridge for scalability
-
Idea Generator Service (
src/idea_generator/)- Uses OpenAI GPT-4 to generate creative video ideas
- Stores ideas with scripts, titles, descriptions, and tags in DynamoDB
-
Video Generator Service (
src/video_generator/)- Integrates with HeyGen or D-ID APIs
- Creates realistic talking head videos from scripts
- Tracks video generation status asynchronously
-
YouTube Uploader Service (
src/youtube_uploader/)- Uploads completed videos to YouTube
- Handles OAuth authentication
- Sets video metadata (title, description, tags)
-
Orchestrator/Scheduler (
src/scheduler/)- Coordinates all services
- Manages the end-to-end workflow
-
API Gateway (
src/api/)- REST API for configuration and manual triggering
- Status monitoring endpoints
1. EventBridge triggers Orchestrator (daily)
↓
2. Orchestrator → Idea Generator
↓ (Generates 5-8 video ideas)
3. Ideas stored in DynamoDB
↓
4. EventBridge triggers Video Generator (every 2 hours)
↓
5. Video Generator picks pending ideas → sends to HeyGen/D-ID
↓ (Async video generation)
6. Status Check (every 15 minutes) → Updates video status
↓
7. EventBridge triggers Upload (at scheduled times: 9am, 1pm, 5pm, 9pm)
↓
8. YouTube Uploader → Downloads video → Uploads to YouTube
↓
9. Video published ✅
-
OpenAI API Key: For idea generation
- Get it from: https://platform.openai.com/api-keys
-
Video API Provider (choose one):
- HeyGen API Key: https://www.heygen.com/
- D-ID API Key: https://www.d-id.com/
-
YouTube OAuth Credentials:
- Create a project in Google Cloud Console
- Enable YouTube Data API v3
- Create OAuth 2.0 credentials
- Get Client ID and Client Secret
- Generate refresh token (see YouTube Setup)
- AWS Account with appropriate permissions
- AWS CLI configured
- Terraform >= 1.0
git clone <repository-url>
cd <repository>
pip install -r requirements.txtBefore deploying, you need to obtain a YouTube refresh token:
# Install required package
pip install google-auth-oauthlib
# Run the OAuth flow helper script
python scripts/get_youtube_token.pyThis will:
- Open your browser for YouTube authorization
- Generate a refresh token
- Display the token to use in Terraform variables
Create terraform/terraform.tfvars:
# AWS Configuration
aws_region = "us-east-1"
project_name = "video-automation"
# API Keys
openai_api_key = "sk-..."
# Choose ONE video provider
video_api_provider = "heygen" # or "did"
heygen_api_key = "..." # If using HeyGen
# did_api_key = "..." # If using D-ID
# YouTube OAuth
youtube_client_id = "....apps.googleusercontent.com"
youtube_client_secret = "..."
youtube_refresh_token = "..."
# Configuration
default_topic = "technology trends"
posting_times = "09:00,13:00,17:00,21:00" # UTC timescd terraform
terraform init
terraform plan
terraform applyThis will create:
- 4 DynamoDB tables
- 5 Lambda functions
- API Gateway with HTTP API
- EventBridge schedules for automation
- IAM roles and permissions
- CloudWatch log groups
# Get the API endpoint
terraform output api_endpoint
# Test health check
curl $(terraform output -raw api_endpoint)/health
# Check system status
curl $(terraform output -raw api_endpoint)/statusOnce deployed, the system runs automatically:
- Daily at 8:00 AM UTC: Generates 8 new video ideas
- Every 2 hours: Initiates video generation for pending ideas
- Every 15 minutes: Checks status of in-progress videos
- At scheduled times (9am, 1pm, 5pm, 9pm UTC): Uploads completed videos to YouTube
curl -X POST https://your-api-endpoint/config/topic \
-H "Content-Type: application/json" \
-d '{"topic": "artificial intelligence breakthroughs"}'curl https://your-api-endpoint/config/topiccurl -X POST https://your-api-endpoint/trigger/ideas \
-H "Content-Type: application/json" \
-d '{"topic": "space exploration", "count": 5}'curl -X POST https://your-api-endpoint/trigger/videoscurl -X POST https://your-api-endpoint/trigger/uploadcurl https://your-api-endpoint/statusResponse:
{
"current_topic": "technology trends",
"pending_ideas": 3,
"generating_videos": 2,
"completed_videos": 1,
"pending_uploads": 0,
"published_videos": 5
}Modify posting_times in terraform.tfvars:
posting_times = "06:00,10:00,14:00,18:00,22:00" # UTC timesAfter changing, run:
terraform applyDefault avatar and voice can be customized in src/video_generator/providers/heygen.py:
"avatar_id": "Angela-inblackskirt-20220820",
"voice_id": "1bd001e7e50f421d891986aad5158bc8"Default presenter and voice in src/video_generator/providers/did.py:
"presenter_image": "https://...",
"voice_id": "en-US-JennyNeural"Modify max_retries in src/common/config.py (default: 3)
View logs for each component:
# Idea Generator
aws logs tail /aws/lambda/video-automation-idea-generator --follow
# Video Generator
aws logs tail /aws/lambda/video-automation-video-generator --follow
# YouTube Uploader
aws logs tail /aws/lambda/video-automation-youtube-uploader --follow
# Orchestrator
aws logs tail /aws/lambda/video-automation-orchestrator --follow
# API
aws logs tail /aws/lambda/video-automation-api --followQuery tables directly:
# List all ideas
aws dynamodb scan --table-name video-automation-ideas
# Check video status
aws dynamodb scan --table-name video-automation-videos
# View upload history
aws dynamodb scan --table-name video-automation-uploads-
Check video generation logs:
aws logs tail /aws/lambda/video-automation-video-generator --follow
-
Verify API key is valid:
# For HeyGen curl -H "X-Api-Key: YOUR_KEY" https://api.heygen.com/v2/avatars # For D-ID curl -H "Authorization: Basic YOUR_KEY" https://api.d-id.com/talks
-
Check DynamoDB for failed videos:
aws dynamodb scan --table-name video-automation-videos \ --filter-expression "status = :status" \ --expression-attribute-values '{":status":{"S":"failed"}}'
-
Verify OAuth token is valid:
- Check Lambda environment variables
- Regenerate refresh token if needed
-
Check upload logs:
aws logs tail /aws/lambda/video-automation-youtube-uploader --follow
-
Verify YouTube API quota:
- Visit Google Cloud Console → APIs & Services → YouTube Data API v3
- Check quota usage
- Check OpenAI API key and quota
- Review idea generator logs
- Verify EventBridge rule is enabled:
aws events describe-rule --name video-automation-idea-generation
- DynamoDB: ~$1-5/month (on-demand pricing)
- Lambda: ~$5-10/month (depending on video count)
- API Gateway: ~$1/month
- CloudWatch Logs: ~$1-2/month
Total AWS: ~$10-20/month
- OpenAI GPT-4: ~$0.03-0.06 per video idea
- HeyGen: ~$0.50-2.00 per video (depending on plan)
- D-ID: ~$0.30-1.00 per video (depending on plan)
- YouTube API: Free (within quota)
For 4 videos/day: ~$60-240/month in API costs
- Never commit API keys - Use Terraform variables and AWS Secrets Manager
- Limit YouTube OAuth scope - Only grant necessary permissions
- Enable CloudWatch alarms - Monitor for unusual activity
- Rotate credentials regularly - Update API keys and OAuth tokens
- Use IAM least privilege - Lambda roles only have necessary permissions
# Set environment variables
export OPENAI_API_KEY="..."
export HEYGEN_API_KEY="..."
# ... other variables
# Test idea generation
python -c "from src.idea_generator.generator import IdeaGenerator; g = IdeaGenerator(); print(g.generate_ideas('AI trends', 2))"
# Test video generation (requires existing idea ID)
python -c "from src.video_generator.generator import VideoGenerator; # ..."# Install dev dependencies
pip install pytest pytest-mock moto
# Run tests
pytest tests/- Create new provider class in
src/video_generator/providers/ - Inherit from
VideoProviderbase class - Implement required methods
- Update
VideoGenerator._get_provider()to support new provider
Modify the prompt in src/idea_generator/generator.py to customize:
- Video length
- Content style
- Target audience
- Script format
Modify EventBridge rules in terraform/eventbridge.tf:
- Change cron expressions
- Add new schedules
- Create conditional triggers
MIT
For issues, questions, or contributions, please open an issue or pull request.
- OpenAI for GPT-4 API
- HeyGen/D-ID for realistic avatar generation
- AWS for serverless infrastructure
- YouTube Data API for video hosting