This project implements a Clickstream Analytics System using AWS services with a Batch Processing Architecture. It handles data collection, raw storage, periodic ETL processing, and analytics visualization using a self-managed PostgreSQL + R Shiny Server running on EC2.
The system emphasizes low cost, scalability, security, and full control of the data warehouse layer.
- Terraform installed (Download Terraform)
- AWS CLI installed and configured (Guide)
- Python 3.x installed with
pip
git clone <repository-url>
cd Iac-Game-Scanterraform initterraform validateterraform plan -out=tfplan
terraform apply tfplanThe system is built using the following AWS services:
- Frontend Hosting: AWS Amplify Hosting (CloudFront integrated)
- Authentication: Amazon Cognito (User Pool)
- API Layer: Amazon API Gateway (HTTP API)
- Data Ingestion: AWS Lambda (Clickstream ingest)
- Raw Data Lake: Amazon S3 (Raw Layer)
- Batch Scheduler: Amazon EventBridge (Cron Job)
- ETL Processor: AWS Lambda ETL
- Private Connectivity: VPC Endpoint Interface
- Internal Routing: Internal ALB
- Data Warehouse & Analytics: EC2 running PostgreSQL + R Shiny Server
- Visualization: Shiny Dashboard
Users access the website through Amplify + CloudFront, which delivers static web assets with low latency.
A JavaScript SDK embedded in the frontend sends user interaction events (clicks, views, searches) to Amazon API Gateway.
API Gateway invokes an AWS Lambda function that validates and stores raw clickstream data into Amazon S3 (Raw Layer).
- Amazon EventBridge triggers the ETL Lambda function every 60 minutes.
- The Lambda function reads raw logs from S3, performs cleaning, transformation, and normalization.
- Processed data is written to S3 Processed Layer and loaded into the EC2 Data Warehouse.
An R Shiny Server on EC2 queries the Data Warehouse to provide dashboards displaying product popularity, customer behavior, sales funnels, and traffic trends.
π¦ Clickstream-Analytics
β£ π infrastructure
β β π terraform
β£ π frontend
β β π React/NextJS source
β£ π lambda
β β£ π ingest.py
β β π etl.py
β£ π scripts
β β π ec2-setup.sh
β£ π shiny
β β π app.R
β π README.md
- Deploy Amplify Hosting
- Configure Cognito User Pool
- Create API Gateway HTTP API
- Deploy Lambda Ingest and ETL
- Create S3 Raw Layer bucket
- Set up EventBridge cron
- Create VPC Endpoint + Internal ALB
- Launch EC2 and install PostgreSQL + Shiny
- Configure ALB β EC2 routing
- Test ingestion β ETL β database workflow
- Access the Shiny dashboard
- Authentication & Authorization: Amazon Cognito manages secure user sign-in and token-based access to APIs.
- Least-privilege IAM Policies are enforced for Lambda, API Gateway, EC2, and S3 access.
- Operational Metrics & Alerts are configured in Amazon CloudWatch and forwarded to Amazon SNS.
- Private subnets ensure no direct public access to the Data Warehouse or Shiny workloads.
- S3 VPC Endpoint ensures internal-only communication without exposing resources to the internet.
- Automatic CI/CD
- CloudFront + S3 integrated
- No server maintenance
- Secure JWT workflow
- Easy integration with API Gateway
- Low cost
- Automatically scalable
- Durable, cheap, ideal for Data Lake
- Flexible cron
- Ideal for periodic ETL processing
- Stateless, scalable ETL jobs
- Converts NoSQL β SQL
- Ensures secure private network communication
- No exposure of EC2 to the internet
- Full control of Data Warehouse
- Ideal for data analytics dashboards


