Skip to content

AlasmariAhmed/lambda-url-shortner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

markdown

🔗 Serverless URL Shortener with QR Code & Analytics

AWS Python QR Code Cost

A production-ready URL shortener with built-in QR code generation and click analytics. Serverless, auto-scaling, and completely free on AWS Free Tier.


📌 Overview

This project implements a full-featured URL shortener using AWS serverless services. Every shortened URL automatically gets a QR code, and all clicks are tracked with detailed analytics.

✨ Features

Feature Description
🔗 URL Shortening Custom or auto-generated 6-character codes
📱 QR Code Generation Automatic SVG QR codes for every short URL
📊 Click Analytics Track total clicks, daily breakdown, device types
🚦 Rate Limiting 100 requests/hour per IP (prevents abuse)
Fast Redirects 301 permanent redirects with caching
🔒 Secure HTTPS only, IAM least privilege
💰 Cost Effective $0/month on AWS Free Tier

🏗️ Architecture

Architecture Diagram

AWS Services Used

Service Purpose Free Tier
Lambda Business logic (Python 3.9) 1M requests/month
API Gateway REST API endpoints with rate limiting 1M requests/month
DynamoDB Single-table design for fast lookups 25 GB storage
S3 QR code caching 5 GB storage
CloudWatch Logging and monitoring 5 GB logs

🚀 Quick Start

Prerequisites

  • AWS Account (Free Tier)
  • Basic AWS Console access
  • 2-3 hours of your time

Deployment Steps

Step Service
1 DynamoDB Table
2 S3 Bucket (QR cache)
3 Lambda Layer (qrcode)
4 Lambda Functions (4)
5 API Gateway
6 Testing

📡 API Documentation

POST /shorten - Create Short URL

Request:

{
  "url": "https://example.com/very/long/url",
  "customCode": "my-link"  // optional, max 20 chars
}
Response:

json
{
  "short_code": "abc123",
  "short_url": "https://your-api/abc123",
  "original_url": "https://example.com/very/long/url",
  "clicks": 0,
  "qr_code_url": "https://your-api/qr/abc123"
}
GET /{shortCode} - Redirect
Response: 301 Permanent Redirect to original URL

GET /analytics/{shortCode} - Get Analytics
Response:

json
{
  "short_code": "abc123",
  "original_url": "https://example.com",
  "total_clicks": 42,
  "last_7_days": {
    "daily_breakdown": {"2026-05-15": 15, "2026-05-14": 27},
    "devices": {"mobile": 30, "desktop": 12}
  },
  "recent_clicks": [...]
}
GET /qr/{shortCode} - Get QR Code
Response: SVG image (QR code encoding the original URL)

Example:

curl https://your-api/qr/abc123 --output qr.svg
💻 Web Frontend
The included code/index.html provides a complete UI with:

Shorten URL tab - Create short URLs with QR codes

Analytics Lookup tab - View analytics for any short code

Copy to clipboard - One-click URL copying

Real-time QR display - SVG QR codes rendered instantly

💰 Cost Breakdown

Service Free Tier Expected Monthly Usage Cost
DynamoDB 25 GB storage 1 MB $0
Lambda 1M requests 1,000 requests $0
API Gateway 1M requests 1,000 requests $0
S3 5 GB storage 100 MB $0
CloudWatch 5 GB logs 1 MB $0

Total: $0/month (AWS Free Tier covers everything)

📸 Screenshots

DynamoDB Table DynamoDb

Lambda Functions Lambda I increased Timeout of QR code generation funcation becuase it is CPU-intensive and exceeds the 3-second default timeout. Lambda I also created a policy that follows the least privilege principle. Lambda

API Gateway APIGateway POST method that will trigger the Lambda funcation APIGateway APIGateway

Web Interface Lambda Lambda Lambda

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors