Skip to content

ajbarea/aws-image-translate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

118 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Lenslate: AI-Powered Image Translator

License: MIT

Lenslate is a cloud-native web application on AWS that lets users upload images to translate embedded text or browse a pre-loaded catalog automatically populated from Reddit's r/translator community and the MMID dataset. Once an image is selected, either manually or from our gallery, Lenslate initiates a high-speed serverless pipeline to extract text, detect its language, and generate translations. Behind the scenes, scalable AWS Lambda functions handle all image processing in a fully serverless architecture with automated deployment scripts and CI/CD testing pipelines.

Core Workflow

  • Reddit & MMID Content Processing: Automated scraping of images from MMID dataset and r/translator using Reddit API via EventBridge-triggered Lambda (every 5 minutes)
  • Amazon Rekognition: AI-powered text detection and extraction from images (OCR)
  • Amazon Comprehend: Auto-detects the source language of extracted text
  • AWS Translate: Converts the extracted text into the user's chosen target language
  • DynamoDB State Management: Tracks processed translations for user Translation History and Reddit duplicate prevention
  • S3 Storage: Secure storage for downloaded images and processed content

All infrastructure is defined and managed with Terraform using a two-stack approach for safe team collaboration. The data-stack contains persistent resources that should never be destroyed (translation history, state management), while the app-stack contains resources that can be safely destroyed and recreated for development. The application features a responsive frontend hosted on S3 with CloudFront distribution, secured with Amazon Cognito for authentication. The backend uses AWS Lambda functions triggered via API Gateway for serverless image processing at scale, plus EventBridge-scheduled Reddit scraping for real-time gallery updates.

⚑ Quick Start

One-Command Deployment

# 1. Clone the repository
git clone <repository-url> && cd lenslate

# 2. Set up environment (optional credentials can be left blank)
cp .env.example .env.local
# Edit .env.local only if you want Reddit gallery population or Google OAuth

# 3. Deploy infrastructure - fully automated!
python deploy.py

That's it! The automated deployment script handles everything:

  • βœ… Validates prerequisites (Terraform, AWS CLI)
  • βœ… Auto-installs missing tools with platform detection
  • βœ… Builds all Lambda functions automatically
  • βœ… Deploys both data-stack and app-stack infrastructure in the correct order
  • βœ… Automatically configures cross-stack dependencies
  • βœ… Provides error handling and auto-fixes
  • βœ… Includes rollback capabilities on deployment failures
  • βœ… Unique resource naming - no conflicts between teammates
  • βœ… Automatic state management with S3 backend

CI/CD Pipeline

Automated testing and build validation via AWS CodePipeline with buildspec.yml:

  • Completely Optional: Only created if GitHub connection ARN is provided
  • Automated Testing: Runs the test suite on commits
  • Lambda Building: Builds all Lambda functions in isolated environment
  • Build Validation: Validates that all Lambda functions can be built successfully
  • Multi-Branch Support: Separate pipelines for different environments
  • Manual Deployment Required: AWS Pipeline prepares artifacts but does not deploy infrastructure as to not overwrite optional Google OAuth and Reddit gallery features

Automated Deployment Features

Our deploy.py script provides fully automated deployment:

  • Prerequisites Validation: Checks and auto-installs Terraform, AWS CLI, Python with platform detection (Windows/macOS/Linux)
  • Configuration Management: Automatically generates terraform.tfvars from .env.local with validation
  • Lambda Build System: Compiles all Lambda functions with dependency management and packaging
  • Two-Stack Deployment: Safely deploys data-stack (persistent) and app-stack (ephemeral) infrastructure in the correct order
  • Cross-Stack Dependencies: Automatically configures app-stack to reference data-stack resources
  • Error Recovery: Intelligent error analysis with suggested fixes and automatic rollback capabilities
  • State Management: Automatic backup and migration of Terraform state with team collaboration support
  • Cross-Platform: Native support for Windows, macOS, and Linux environments
  • CI/CD Integration: Compatible with AWS CodeBuild for automated testing and build validation

Infrastructure as Code (IaC)

Two-Stack Architecture for Safe Team Collaboration

Data Stack (terraform/data-stack/):

  • Persistent shared infrastructure - never destroyed
  • S3 backend for Terraform state management
  • DynamoDB for state locking
  • Core shared resources (translation tables, history tables)
  • Safe from terraform destroy - only deployed once per team

App Stack (terraform/app-stack/):

  • Ephemeral application resources - safe to destroy and recreate
  • Cognito user pools, Lambda functions, API Gateway
  • CloudFront distribution, S3 buckets
  • EventBridge rules, Reddit processing infrastructure
  • Can be terraform destroyed for testing and development
  • Automatically references data-stack - cross-stack dependencies handled by deploy script

This separation ensures that critical data (user translations, history) is preserved in the data-stack while allowing developers to freely experiment with app-stack resources. The data-stack acts as a foundation that persists across multiple app-stack deployments. The automated deployment script handles the complex cross-stack dependency configuration automatically.

AWS Resources Provisioned

  • Cognito: User authentication and identity pools
  • S3: Image storage bucket and frontend hosting bucket
  • Lambda: Serverless image processing functions
  • DynamoDB: User translation history and session management
  • API Gateway: RESTful endpoints for frontend-backend communication
  • CloudFront: Content delivery network for global frontend distribution
  • EventBridge: Scheduled Reddit scraping (every 5 minutes)
  • IAM: Roles and policies for secure service-to-service communication

Architecture Overview

System Components

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Frontend      β”‚    β”‚   API Gateway    β”‚    β”‚   Lambda        β”‚
β”‚   (S3/CF)       │◄──►│   (REST API)     │◄──►│   Functions     β”‚
β”‚                 β”‚    β”‚                  β”‚    β”‚                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                       β”‚                       β”‚
         β–Ό                       β–Ό                       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Cognito       β”‚    β”‚   S3 Storage     β”‚    β”‚   DynamoDB      β”‚
β”‚   (Auth)        β”‚    β”‚   (Images)       β”‚    β”‚   (State)       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚                       β–²
                                β–Ό                       β”‚
                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”             β”‚
                       β”‚   AWS AI/ML      β”‚β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                       β”‚   Services       β”‚
                       β”‚   (Rekognition,  β”‚
                       β”‚   Comprehend,    β”‚
                       β”‚   Translate)     β”‚
                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Data Flow

  1. User Interaction: Users access the frontend via CloudFront/S3, authenticate with Cognito
  2. Image Upload: Images uploaded to S3 trigger processing workflows
  3. API Communication: Frontend communicates with Lambda via API Gateway
  4. AI Processing: Lambda functions use Rekognition for text extraction, Comprehend for language detection, Translate for conversion
  5. State Management: DynamoDB tracks processing state for Reddit pipeline and user sessions

Reddit Pipeline with EventBridge

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   EventBridge   β”‚    β”‚   Lambda         β”‚    β”‚   Reddit API    β”‚
β”‚   (5min timer)  │───►│   Scraper        │◄──►│   (PRAW)        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚                       β”‚
                                β–Ό                       β–Ό
                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                       β”‚   DynamoDB       β”‚    β”‚   S3 Storage    β”‚
                       β”‚   (State Track)  β”‚    β”‚   (Images)      β”‚
                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Project Structure

lenslate/
β”œβ”€β”€ deploy.py               # Automated deployment orchestrator
β”œβ”€β”€ buildspec.yml           # CI/CD testing and build configuration
β”œβ”€β”€ package.json            # Frontend JavaScript dependencies and test scripts
β”œβ”€β”€ jest.config.js          # Jest testing configuration
β”œβ”€β”€ pyproject.toml          # Python project configuration
β”œβ”€β”€ LICENSE.md              # MIT license
β”œβ”€β”€ README.md               # Project documentation
β”œβ”€β”€ deployment_logic/       # Deployment automation modules
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ deployment_orchestrator.py # Main deployment logic
β”‚   β”œβ”€β”€ feature_handler.py  # Optional feature configuration
β”‚   β”œβ”€β”€ progress_indicator.py # Console output formatting
β”‚   β”œβ”€β”€ python_detector.py  # Python environment detection
β”‚   └── resource_naming.py  # Unique resource name generation
β”œβ”€β”€ lambda_functions/       # AWS Lambda functions
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ build_all.py        # Lambda build system
β”‚   β”œβ”€β”€ build_lambda.py     # Individual Lambda builder
β”‚   β”œβ”€β”€ image_processor.py  # Main image processing and translation
β”‚   β”œβ”€β”€ reddit_populator_sync.py # Bulk Reddit scraping for initial population
β”‚   β”œβ”€β”€ reddit_realtime_scraper.py # Real-time Reddit post processing via EventBridge
β”‚   β”œβ”€β”€ reddit_scraper_sync.py # Core Reddit API integration with PRAW
β”‚   β”œβ”€β”€ mmid_populator.py   # MMID dataset image sampling
β”‚   β”œβ”€β”€ gallery_lister.py   # Gallery listing functionality
β”‚   β”œβ”€β”€ cognito_triggers.py # Authentication triggers
β”‚   β”œβ”€β”€ user_manager.py     # User management functions
β”‚   β”œβ”€β”€ history_handler.py  # Translation history management
β”‚   β”œβ”€β”€ aws_clients.py      # AWS service clients with circuit breakers
β”‚   β”œβ”€β”€ prepare_reddit_populator.py # Reddit Lambda preparation script
β”‚   β”œβ”€β”€ requirements.txt    # Lambda dependencies
β”‚   └── build/             # Build artifacts directory
β”‚       └── reddit_populator/ # Built Reddit Lambda package
β”œβ”€β”€ tests/                  # Test suite
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ setup.js           # JavaScript test setup
β”‚   β”œβ”€β”€ test-utils.js      # JavaScript test utilities
β”‚   β”œβ”€β”€ auth.test.js       # Authentication unit tests
β”‚   β”œβ”€β”€ auth-integration.test.js # Authentication integration tests
β”‚   β”œβ”€β”€ auth-performance.test.js # Authentication performance tests
β”‚   β”œβ”€β”€ test_buildspec.py  # CI/CD testing pipeline tests
β”‚   β”œβ”€β”€ test_deploy.py     # Deployment automation tests
β”‚   β”œβ”€β”€ test_deployment_orchestrator.py # Deployment orchestrator tests
β”‚   β”œβ”€β”€ test_feature_handler.py # Feature handler tests
β”‚   β”œβ”€β”€ test_history_handler.py # History handler unit tests
β”‚   β”œβ”€β”€ test_mmid_populator.py # MMID populator unit tests
β”‚   β”œβ”€β”€ test_progress_indicator.py # Progress indicator tests
β”‚   β”œβ”€β”€ test_python_detector.py # Python detector tests
β”‚   └── test_resource_naming.py # Resource naming tests
β”œβ”€β”€ frontend/               # Web application
β”‚   β”œβ”€β”€ favicon.ico        # Website favicon
β”‚   β”œβ”€β”€ index.html         # Main application page
β”‚   β”œβ”€β”€ css/
β”‚   β”‚   └── styles.css     # Modern responsive styling
β”‚   β”œβ”€β”€ js/                # JavaScript modules
β”‚   β”‚   β”œβ”€β”€ app.js         # Main application orchestrator
β”‚   β”‚   β”œβ”€β”€ auth.js        # Authentication management
β”‚   β”‚   β”œβ”€β”€ component-loader.js # Dynamic HTML component loader
β”‚   β”‚   β”œβ”€β”€ config.js      # AWS configuration (generated by Terraform)
β”‚   β”‚   β”œβ”€β”€ config.js.template # Configuration template
β”‚   β”‚   β”œβ”€β”€ components/    # JavaScript component classes
β”‚   β”‚   β”‚   β”œβ”€β”€ AuthComponent.js # Authentication UI
β”‚   β”‚   β”‚   β”œβ”€β”€ BaseComponent.js # Base component class
β”‚   β”‚   β”‚   β”œβ”€β”€ DashboardComponent.js # User dashboard
β”‚   β”‚   β”‚   β”œβ”€β”€ FileUploadComponent.js # File upload handling
β”‚   β”‚   β”‚   β”œβ”€β”€ FlipModalComponent.js # Image translation modal
β”‚   β”‚   β”‚   β”œβ”€β”€ GalleryComponent.js # Image gallery
β”‚   β”‚   β”‚   β”œβ”€β”€ LanguageSelectionComponent.js # Language picker
β”‚   β”‚   β”‚   β”œβ”€β”€ ProfileComponent.js # User profile management
β”‚   β”‚   β”‚   β”œβ”€β”€ ResultsComponent.js # Translation results display
β”‚   β”‚   β”‚   └── UploadQueueComponent.js # Upload queue management
β”‚   β”‚   └── constants/
β”‚   β”‚       └── languages.js # AWS Translate language definitions
β”‚   β”œβ”€β”€ components/        # HTML component templates
β”‚   β”‚   β”œβ”€β”€ confirmation-form.html # Email confirmation form
β”‚   β”‚   β”œβ”€β”€ dashboard.html # User dashboard layout
β”‚   β”‚   β”œβ”€β”€ file-upload.html # File upload interface
β”‚   β”‚   β”œβ”€β”€ gallery.html   # Image gallery layout
β”‚   β”‚   β”œβ”€β”€ header.html    # Page header
β”‚   β”‚   β”œβ”€β”€ language-selection.html # Language selection dropdown
β”‚   β”‚   β”œβ”€β”€ login-form.html # Login form
β”‚   β”‚   β”œβ”€β”€ profile.html   # User profile interface
β”‚   β”‚   β”œβ”€β”€ register-form.html # Registration form
β”‚   β”‚   └── upload-list.html # Upload queue display
β”‚   └── resources/         # Static assets
β”‚       β”œβ”€β”€ google-logo.svg # Google OAuth logo
β”‚       β”œβ”€β”€ lenslate-logo.png # Application logo
β”‚       └── images/        # Image assets directory
β”œβ”€β”€ terraform/              # Infrastructure as Code (Two-Stack Architecture)
β”‚   β”œβ”€β”€ reddit_populator.zip # Pre-built Lambda package
β”‚   β”œβ”€β”€ data-stack/        # Persistent infrastructure - never destroyed
β”‚   β”‚   β”œβ”€β”€ main.tf        # Provider configuration and random ID
β”‚   β”‚   β”œβ”€β”€ backend.tf     # S3 backend and DynamoDB state lock
β”‚   β”‚   β”œβ”€β”€ dynamodb.tf    # Translation and history tables
β”‚   β”‚   β”œβ”€β”€ locals.tf      # Local variables and naming
β”‚   β”‚   β”œβ”€β”€ outputs.tf     # Shared resource outputs
β”‚   β”‚   └── variables.tf   # Input variables
β”‚   └── app-stack/         # Ephemeral application resources - safe to destroy
β”‚       β”œβ”€β”€ main.tf        # Provider and auto-generation configuration
β”‚       β”œβ”€β”€ data.tf        # Data sources and remote state
β”‚       β”œβ”€β”€ locals.tf      # Local variables and common tags
β”‚       β”œβ”€β”€ variables.tf   # Input variables
β”‚       β”œβ”€β”€ lambda.tf      # Lambda function definitions with EventBridge integration
β”‚       β”œβ”€β”€ s3.tf          # S3 bucket configuration
β”‚       β”œβ”€β”€ cognito.tf     # Authentication setup
β”‚       β”œβ”€β”€ dynamodb.tf    # Reddit processing tables
β”‚       β”œβ”€β”€ eventbridge.tf # Reddit scraping schedule (every 5 minutes)
β”‚       β”œβ”€β”€ api.tf         # API Gateway configuration
β”‚       β”œβ”€β”€ frontend.tf    # S3 hosting and CloudFront
β”‚       β”œβ”€β”€ google-oauth.tf # Google OAuth configuration
β”‚       β”œβ”€β”€ oauth-automation.tf # OAuth automation with Secrets Manager
β”‚       β”œβ”€β”€ codepipeline.tf # CI/CD testing pipeline infrastructure
β”‚       β”œβ”€β”€ outputs.tf     # Resource outputs
β”‚       β”œβ”€β”€ config.js.tpl  # JavaScript config template
β”‚       β”œβ”€β”€ env_to_tfvars.py # Environment variable to Terraform vars converter
β”‚       β”œβ”€β”€ post_deploy_message.py # Post-deployment messaging
β”‚       β”œβ”€β”€ sync_frontend.py # Frontend synchronization script
β”‚       β”œβ”€β”€ update-google-oauth.py # Google OAuth update automation
β”‚       └── user_reset.sh  # User management utilities
└── .env.example           # Environment variable template

Team

Prerequisites

Required Software & Tools

  • Terraform - Infrastructure as code deployment
  • AWS CLI - Configure with your AWS credentials
  • Python - Backend services and Lambda functions
  • Git - Version control for cloning the repository

Required Accounts & Access

  • AWS Account - REQUIRED for all AWS services

  • Reddit Account & API Access - OPTIONAL for automated gallery population

  • Google OAuth - COMPLETELY OPTIONAL for "Sign in with Google" functionality

    • Google Cloud Console (optional)
    • Note: If not provided, the Google sign-in button is automatically hidden

Setup Verification

Before proceeding, verify your setup:

# Check required tools
terraform --version
aws --version
python --version
git --version

# Verify AWS credentials
aws sts get-caller-identity

Important: The aws sts get-caller-identity command must work without errors. This is the only mandatory credential requirement for deployment.

How to Deploy

Option 1: Automated Deployment (Recommended)

Single command deployment with full automation:

  1. Clone and setup environment

    git clone <repository-url>
    cd lenslate
  2. Configure credentials (optional)

    cp .env.example .env.local
    # Edit .env.local if you want Reddit gallery population or Google OAuth
  3. Deploy everything automatically

    python deploy.py

The automated deployment script:

  • βœ… Validates all prerequisites (Terraform, AWS CLI) with version checking
  • βœ… Auto-installs missing tools on Windows/macOS/Linux
  • βœ… Builds all Lambda functions with dependency management
  • βœ… Generates terraform.tfvars automatically from .env.local
  • βœ… Deploys data-stack (persistent infrastructure) and app-stack (ephemeral resources) in the correct order
  • βœ… Automatically configures cross-stack dependencies
  • βœ… Provides error analysis and auto-fixes
  • βœ… Includes rollback capabilities on failures
  • βœ… Cross-platform compatibility
  • βœ… CI/CD integration with buildspec.yml for testing and build validation

Option 2: CI/CD Pipeline

Automated testing and build validation via AWS CodePipeline:

The repository includes a complete CI/CD pipeline configuration:

  • buildspec.yml: Defines test and build validation steps
  • CodeBuild integration: Automated testing and Lambda building
  • Multi-environment support: Separate pipelines for different branches
  • Secrets management: Uses AWS Secrets Manager for credentials

Commits to configured branches trigger automatic testing and build validation. Manual deployment using python deploy.py is required to deploy the infrastructure.

Credential Configuration

REQUIRED:

  • AWS CLI: Must be configured with aws configure

OPTIONAL (for enhanced features):

What happens if you skip optional credentials:

  • No Reddit credentials: Gallery still works with MMID dataset images, Reddit features disabled
  • No Google OAuth: Users can still authenticate with Cognito email/password, Google sign-in button hidden

Customizing Reddit Subreddits

By default, Lenslate monitors r/translator for images with translatable text. You can easily customize this to monitor multiple subreddits by editing your .env.local file:

# Reddit Subreddits Configuration
# Add subreddits as a comma-separated list (no spaces around commas)
REDDIT_SUBREDDITS=translator,language

Examples:

  • REDDIT_SUBREDDITS=translator - Monitor only r/translator (default)
  • REDDIT_SUBREDDITS=translator,language - Monitor r/translator and r/language
  • REDDIT_SUBREDDITS=translator,language,LearnJapanese - Monitor multiple language-related subreddits

The configuration is centralized - changing this one line in .env.local updates:

  • βœ… EventBridge scheduled scraping (every 5 minutes)
  • βœ… Initial bulk population during deployment
  • βœ… All Lambda functions that process Reddit content

3. Access Your Application

Use the CloudFront URL provided in the Terraform outputs to access your live application!

4. Development

For local development and testing:

# Sync frontend changes to S3/CloudFront
cd terraform/app-stack
python sync_frontend.py

# Update Google OAuth configuration after deployment
python update-google-oauth.py

# Frontend localhost at 8000
cd ../../frontend
python -m http.server 8000

Note: Google OAuth may not work when running locally on localhost

5. Testing

The project includes tests for deployment automation, Lambda functions, and frontend components:

Deployment Tests:

# Install Python test dependencies
pip install -e ".[testing]"

# Test automated deployment system
pytest tests/test_deploy.py -v

# Test CI/CD buildspec testing configuration
pytest tests/test_buildspec.py -v

Lambda Function Tests:

# Run all Python Lambda tests
pytest tests/test_*.py

# Run tests with coverage
pytest tests/ --cov=lambda_functions --cov-report=html

# Run specific test file
pytest tests/test_history_handler.py

Frontend JavaScript Tests:

# Run all JavaScript tests
npm test

# Run specific test file
npm test auth.test.js

# Run tests with coverage
npm test -- --coverage

# Run tests in watch mode
npm test -- --watch

The test suite includes:

  • Deployment Tests: Testing of deploy.py automation

    • Prerequisites validation testing
    • Terraform integration testing
    • CI/CD pipeline compatibility testing
    • Cross-platform deployment validation
  • Python Tests: Mock-based testing of Lambda functions using pytest

    • Unit Tests: Individual Lambda function testing
    • Integration Tests: Using moto library to simulate AWS services
    • Edge Case Testing: Error condition coverage
    • DynamoDB Testing: Full simulation of database operations
  • JavaScript Tests: Frontend component testing using Jest

    • Authentication module tests (auth.test.js)
    • UI component tests
    • Mock AWS SDK interactions
    • Browser environment simulation

6. Clean Up

When you're done testing, easily destroy all AWS resources:

# Using automated script (recommended - handles both stacks safely)
python deploy.py --destroy

# Or manually (app-stack only - data-stack should be preserved)
cd terraform/app-stack
terraform destroy

Important: Only destroy the app-stack manually. The data-stack contains persistent resources (translation history, state management) that should be preserved across deployments.

This removes all AWS resources and stops charges. Your .env.local file remains for future deployments.

Note: The automated --destroy command safely handles both stacks in the correct order and includes user confirmation prompts for safety.

πŸ”§ Troubleshooting

Common Deployment Issues

"Python/Terraform/AWS CLI not found"

The deploy.py script automatically detects and installs missing prerequisites:

  • Windows: Uses winget or choco for automatic installation
  • macOS: Uses brew for automatic installation
  • Linux: Uses apt or yum for automatic installation

Or install manually:

"AWS credentials not configured"

  • Run aws configure and provide your AWS Access Key ID and Secret Access Key
  • Test with aws sts get-caller-identity
  • The deploy.py script validates credentials automatically

"Lambda build failed"

The deployment script provides intelligent error analysis:

  • Dependency issues: Automatically retries pip installations
  • Permission errors: Suggests running as administrator when needed
  • Network issues: Provides connectivity troubleshooting steps

Run manually for debugging:

cd lambda_functions
python build_all.py --verbose

"Terraform deployment failed"

The deployment script includes automatic error recovery:

  • State lock issues: Provides lock resolution commands
  • Resource conflicts: Auto-generates unique resource names
  • Rollback capability: Automatically reverts on critical failures

"Reddit features not working"

  • This is expected if you didn't provide Reddit credentials
  • The app still works with MMID dataset images
  • Add Reddit credentials to .env.local and run python deploy.py again

"Google Sign-in button missing"

  • This is expected if you didn't provide Google OAuth credentials
  • Users can still authenticate with email/password via Cognito
  • Add Google OAuth credentials to .env.local and run terraform apply again if needed

Known Issues

Python Executable Compatibility

The deploy.py script is currently hardcoded to use the python command and may not work in environments where you need to use python3:

  • Works with: Systems where python points to Python 3.x (Windows, some Linux distributions, CI/CD environments)
  • May not work with: Systems where only python3 is available (some Linux/macOS configurations)
  • Workaround: Create a symlink or alias from python3 to python, or use a virtual environment where python is available
  • Background: Cross-platform Python executable detection proved challenging across different shell environments, so we standardized on python for consistency with our CI/CD pipeline

This affects the automated deployment script but does not impact the deployed application functionality.

Deployment Benefits

The Terraform deployment provides:

  • πŸ” Secure Credential Management: Store sensitive credentials in .env.local (gitignored)
  • πŸ”„ Automatic Configuration: Terraform automatically generates terraform.tfvars from .env.local
  • πŸš€ Zero-Config Deployment: Single python deploy.py command handles the entire deployment pipeline
  • πŸ›‘οΈ Graceful Degradation: Missing optional credentials automatically disable related features instead of breaking
  • ⚑ Rapid Iteration: Quick redeployment for testing changes
  • 🎯 Minimal Requirements: Only AWS CLI configuration required - everything else is optional
  • πŸ”— Cross-Stack Dependencies: Automatic handling of complex infrastructure dependencies

Data Sources and Dependencies

  • Reddit API Integration: Images are sourced from r/translator using Python Reddit API Wrapper (PRAW)
  • MMID Dataset Integration: Automated sampling from the Multilingual Multimodal Image Dataset (MMID) - a public dataset containing images with text in multiple languages (Chinese, Hindi, Spanish, Arabic, French). The lambda_functions/mmid_populator.py function automatically downloads and populates your S3 bucket with diverse multilingual images for testing and demonstration.
  • AWS Services: S3, Lambda, DynamoDB, Rekognition, Comprehend, Translate, Cognito, API Gateway, CloudFront, EventBridge
  • Backend Stack: Python 3.11+ with boto3, asyncio for concurrent processing, PRAW for Reddit API
  • Frontend Stack: Vanilla JavaScript with AWS SDK for browser, HTML5, and modern CSS with component-based architecture
  • Infrastructure: All resources managed via Terraform with automated deployment system and two-stack architecture
  • CI/CD: AWS CodePipeline with CodeBuild for automated testing and build validation

Production-Ready Features

The application is fully functional with enterprise-grade infrastructure:

  • βœ… Automated Deployment: One-command deployment with validation and error recovery
  • βœ… CI/CD Pipeline: AWS CodePipeline with automated testing and deployment
  • βœ… Two-Stack Architecture: Separation of persistent data infrastructure and ephemeral application resources
  • βœ… Reddit Streaming: EventBridge-triggered real-time Reddit scraping from r/translator (every 5 minutes)
  • βœ… Backend Pipeline: Automated image processing with AWS AI/ML services
  • βœ… Web Interface: Complete frontend with authentication, file upload, and translation display
  • βœ… Team Collaboration: Environment-specific resource naming with shared state management

Key Features

Automated Deployment System

  • Prerequisites Validation: Automatic detection and installation of Terraform, AWS CLI
  • Cross-Platform Support: Windows, macOS, and Linux compatibility
  • Error Recovery: Intelligent error analysis with suggested fixes and auto-rollback
  • Lambda Build System: Automated compilation of all Lambda functions with dependency management
  • Configuration Auto-Fix: Resolves common configuration issues automatically
  • CI/CD Integration: Non-interactive mode for CodeBuild and other automation systems

Frontend Application

  • Authentication: Secure user registration and login via AWS Cognito with optional Google OAuth
  • File Upload: Drag-and-drop interface with progress tracking
  • Real-time Processing: Live status updates during image processing
  • Multi-language Support: Translation between 70+ languages
  • Results Display: Side-by-side comparison of original and translated text
  • Gallery Browsing: Pre-loaded images from Reddit and MMID dataset

Backend Pipeline

  • Asynchronous Processing: Concurrent handling of multiple images using asyncio
  • State Management: Persistent tracking via DynamoDB with environment-specific tables
  • Error Handling: Error recovery and logging with circuit breakers
  • Scalable Architecture: Serverless Lambda functions with automatic scaling
  • API Integration: RESTful endpoints for frontend-backend communication
  • EventBridge Scheduling: Automated Reddit scraping every 5 minutes

Content Integration

  • Reddit Streaming: Real-time monitoring of r/translator with EventBridge triggers every 5 minutes
  • MMID Dataset: Automatic sampling of multilingual images from the public MMID dataset
  • Image Filtering: Smart detection of image posts with text content using AI/ML services
  • Duplicate Prevention: Advanced content hashing and state tracking to avoid reprocessing images
  • Batch Processing: Efficient handling of multiple posts per execution with concurrent processing
  • Real-time Updates: Gallery auto-refreshes to show new Reddit images as they're processed

How to Access and Use

Web Interface

  1. Access the application: Navigate to the CloudFront URL provided in deployment outputs
  2. Authentication: Create an account or log in using Cognito authentication (with optional Google OAuth)
  3. Upload or Browse images: Choose between two experiences:
    • Upload: Use the drag-and-drop interface to upload your own images for translation
    • Browse: Explore pre-loaded images from Reddit's r/translator subreddit and the MMID multilingual dataset
  4. Interactive browsing: For Reddit images, click on any image to flip it over and reveal the translation interface
  5. Select target language: Choose from AWS supported languages (English, Spanish, French, German, etc.)
  6. Process images: Click "Process" to extract and translate text from images
  7. View results: See both original detected text and translated text side-by-side

Backend Processing (AWS Lambda)

  1. Automated processing: The system uses AWS Lambda functions for:

    • S3 triggers: Automatically process images uploaded to S3
    • API Gateway: Handle web interface requests
    • EventBridge triggers: Scheduled Reddit scraping every 5 minutes from r/translator
    • Real-time streaming: Captures new images from r/translator as they are submitted
  2. Lambda deployment: The image processing logic is deployed as AWS Lambda functions:

    • lambda_functions/image_processor.py: Main image processing and translation logic
    • lambda_functions/reddit_populator_sync.py: Reddit scraping with EventBridge integration
    • lambda_functions/cognito_triggers.py: Authentication and user management

Development Workflow

To avoid merge conflicts, regularly update your feature branch with the latest changes from the remote repository. Follow this workflow to keep your branch up to date and minimize issues:

  1. Fetch the latest from remote

    git fetch origin
  2. Switch to and update develop

    git checkout develop
    git pull origin develop
  3. Create your feature branch off the updated develop

    git checkout -b feature/your-branch
  4. Push the new branch and set its upstream

    git push -u origin feature/your-branch
  5. Work on your code: commit locally as you go.

  6. Before you push or at the start of each dev session, sync your branch with develop

    git fetch origin
    git checkout feature/your-branch
    git merge origin/develop
  7. Resolve any conflicts, run your tests, and THEN you can push

    git push origin feature/your-branch

Doing this will catch conflicts early in your own branch, keep your PRs clean, and save everyone a huge headache when it’s time to merge and approve PRs.

License

MIT License

See LICENSE for details.

About

Image translation system using AWS services

Resources

Stars

Watchers

Forks

Contributors