AWS Serverless Project: Video Upload and Playback Application

PRAFUL PATEL โ๏ธ๐, Highly skilled and motivated Cloud Engineer with a proven track record of designing, implementing, and managing robust cloud infrastructure solutions. With years of hands-on experience, I am deeply passionate about creating scalable and resilient cloud architectures that drive innovation and deliver optimal business outcomes. ๐ Key Competencies:
Cloud Platforms: AWS, Azure, GCP, OCI Infrastructure as Code: Terraform, Ansible Containers & Orchestration: Docker, Kubernetes Scripting: Python, Bash/Shell CI/CD & Version Control: GitHub, Jenkins, CircleCI Monitoring & Analytics: Grafana, Prometheus, Datadog, New Relic Backup & Recovery: Veeam Operating Systems: Linux, Windows DevOps Tools: AWS Code Build, Code Pipeline, Azure DevOps
๐ Continuous Learning: Staying ahead in the rapidly evolving cloud landscape is my priority. I am committed to expanding my skill set and embracing emerging cloud technologies to drive efficiency and innovation. Passionate Cloud/DevOps enthusiast dedicated to designing, building, and deploying cutting-edge technology solutions. As a devoted YouTuber, I love sharing insights through informative videos and crafting technical blogs that delve into areas like โ๏ธ Cloud, ๐ ๏ธ DevOps, ๐ง Linux, and ๐ฆ Containers. ๐ป Open Source Advocate: Contributing to open-source projects is a vital part of my journey. I actively engage in projects centered around Cloud, DevOps, Linux, and Containers, fostering collaboration and innovation within the community. ๐ Let's Connect: I am enthusiastic about virtual collaborations and meeting fellow professionals. Let's explore how I can contribute to your organization's cloud goals. Feel free to connect or DM me.
๐ Portfolio: Check out my portfolio ๐ LinkedIn: Connect on LinkedIn ๐ ๏ธ GitHub: Explore my projects ๐ฅ YouTube: Watch my videos ๐ Medium: Read my articles ๐ Dev.to: Check out my posts
Overview
This project showcases a fully serverless video upload and playback application built using AWS services. The application enables users to upload videos, store them in Amazon S3, and manage metadata in DynamoDB. Videos can then be fetched and played seamlessly through a modern web interface. The architecture is scalable, secure, and cost-effective.
๐ Follow Project on GitHub Repo Link: https://github.com/prafulpatel16/video-app-aws-serverless/blob/master/README.md ๐โจ
Architecture Diagram
Key Features
Upload videos directly from the frontend to S3.
Store video metadata in DynamoDB.
Fetch and play videos via a modern web interface.
Tech Stack
Frontend: HTML, CSS, JavaScript
Backend: AWS Lambda, API Gateway
Database: DynamoDB
Storage: S3
Monitoring: CloudWatch
Step-by-Step Implementation
1. Setting Up Amazon S3 for Video Storage
Create an S3 Bucket:
aws s3 mb s3://video-upload-bucket

Configure CORS:
[ { "AllowedHeaders": ["*"], "AllowedMethods": ["GET", "PUT", "POST"], "AllowedOrigins": ["*"] } ]Enable Static Website Hosting:
Go to the Properties tab in the S3 console.
Set Index Document to
index.html.

Sync Frontend Files:
aws s3 sync static-web/ s3://video-upload-bucket
2. Setting Up DynamoDB for Metadata Storage
Create a DynamoDB Table:
aws dynamodb create-table \ --table-name video-metadata \ --attribute-definitions AttributeName=videoId,AttributeType=S \ --key-schema AttributeName=videoId,KeyType=HASH \ --billing-mode PAY_PER_REQUEST


3. Creating Lambda Functions
Upload Handler
This function uploads videos to S3 and saves metadata in DynamoDB.
import boto3
import json
import os
import uuid
s3 = boto3.client('s3')
dynamodb = boto3.resource('dynamodb')
BUCKET_NAME = os.environ['BUCKET_NAME']
TABLE_NAME = os.environ['TABLE_NAME']
def lambda_handler(event, context):
try:
file_content = event['body']
file_name = f"{uuid.uuid4()}.mp4"
# Upload video to S3
s3.put_object(Bucket=BUCKET_NAME, Key=file_name, Body=file_content)
# Save metadata to DynamoDB
table = dynamodb.Table(TABLE_NAME)
table.put_item(
Item={
'videoId': file_name,
'url': f"https://{BUCKET_NAME}.s3.amazonaws.com/{file_name}"
}
)
return {
"statusCode": 200,
"headers": {"Access-Control-Allow-Origin": "*"},
"body": json.dumps({"message": "File uploaded successfully"})
}
except Exception as e:
return {
"statusCode": 500,
"headers": {"Access-Control-Allow-Origin": "*"},
"body": json.dumps({"error": str(e)})
}

Fetch Handler
This function retrieves video metadata from DynamoDB.
import boto3
import json
import os
dynamodb = boto3.resource('dynamodb')
TABLE_NAME = os.environ['TABLE_NAME']
def lambda_handler(event, context):
try:
table = dynamodb.Table(TABLE_NAME)
response = table.scan()
return {
"statusCode": 200,
"headers": {"Access-Control-Allow-Origin": "*"},
"body": json.dumps(response['Items'])
}
except Exception as e:
return {
"statusCode": 500,
"headers": {"Access-Control-Allow-Origin": "*"},
"body": json.dumps({"error": str(e)})
}

4. Configuring API Gateway
Create an API:
Go to API Gateway > Create API.
Choose HTTP API and name it
video-app-api.
Add Routes:
POST
/uploadโvideo-upload-handler.GET
/fetchโvideo-fetch-handler.
Enable CORS:
Add headers:
Access-Control-Allow-Origin: *Access-Control-Allow-Methods: GET, POST, OPTIONS


5. Hosting Frontend on S3
Sync the frontend files:
aws s3 sync static-web/ s3://video-upload-bucket
6. Testing the Application
Open the static website URL in your browser.
Upload videos and fetch metadata to test the functionality.
Monitoring and Optimization
Enable CloudWatch Logs for Lambda functions to monitor errors and performance.
Use CloudFront to distribute video content globally for faster playback.
Challenges and Solutions
CORS Issues:
- Ensure proper headers are configured in API Gateway and Lambda responses.
Large File Uploads:
- Use multipart uploads for better performance with large files.
Conclusion
This AWS serverless project demonstrates the power of building scalable, cost-efficient, and secure video upload and playback systems. By leveraging AWS services like S3, DynamoDB, Lambda, and API Gateway, developers can deliver high-quality user experiences without managing server infrastructure. This architecture is ideal for real-time video applications.




