Skip to main content

Core serverless video transcoding and API backend for StreamVault.

Project description

StreamVault Core SDK

streamvault-core-kaustubh is a serverless Python SDK that simplifies building event-driven AWS video streaming pipelines. It provides pre-built logic for FFmpeg MPEG-DASH transcoding, DynamoDB job tracking, and a RESTful backend with Role-Based Access Control (RBAC).

🚀 Installation

Install the library directly from PyPI (once published):

pip install streamvault-core-kaustubh

🏗️ Prerequisites

To use this SDK in AWS Lambda, your architecture requires:

  1. Source S3 Bucket: Where raw MP4s are uploaded.
  2. Distribution S3 Bucket: Where .mpd and .m4s segments are stored.
  3. DynamoDB Table: A single-table design for tracking users and transcoding jobs (Partition Key: PK, string).
  4. FFmpeg Lambda Layer: An AWS Lambda Layer providing the ffmpeg binary at /opt/python/bin/ffmpeg.

🎬 1. Video Transcoder Implementation

Create an AWS Lambda function triggered by S3 ObjectCreated events on your Source bucket. This function uses the process_video_s3_trigger wrapper to automatically download the video, transcode it to MPEG-DASH, push to the Distribution bucket, and send an SNS alert!

# lambda_function.py
import streamvault

import os

def lambda_handler(event, context):
    # Retrieve required environment variables
    table_name = os.environ["DYNAMODB_TABLE_NAME"]
    output_bucket = os.environ["OUTPUT_BUCKET"]
    sns_topic = os.environ.get("SNS_TOPIC_ARN", None)
    
    # 💥 StreamVault Magic
    streamvault.process_video_s3_trigger(
        event=event,
        table_name=table_name,
        output_bucket=output_bucket,
        sns_topic_arn=sns_topic
    )
    
    return {
        "statusCode": 200,
        "body": "Transcoding workflow triggered successfully!"
    }

🛡️ 2. API Gateway & User Registration Implementation

Create a second AWS Lambda function strictly for handling API Gateway requests. This function provides instant backend routes for: user registration, logging in, role-based video retrieval, video deletion, and group access assignments.

# api_lambda_function.py
import streamvault
import os

def lambda_handler(event, context):
    # Retrieve required environment variables
    table_name = os.environ["DYNAMODB_TABLE_NAME"]
    source_bucket = os.environ["SOURCE_BUCKET"]
    
    # 💥 StreamVault Magic
    return streamvault.handle_api_request(
        event=event,
        table_name=table_name,
        source_bucket=source_bucket
    )

Supported API Routes:

If your API Gateway endpoint is https://api.example.com, you instantly have access to:

  • GET ?action=jobs - Retrieve all background transcoding job statuses (Admin).
  • GET ?action=videos&group=[Group] - Retrieve successfully transcoded videos the user has access to.
  • POST ?action=signup&username=[User]&password=[Pass]&group=[Plan] - Register a new user in the DB.
  • GET ?action=login&username=[User]&password=[Pass] - Returns profile information and group tier.
  • GET ?action=upload-url&filename=[Name.mp4] - Generates an S3 Pre-signed URL for direct uploads.
  • DELETE ?action=delete&id=[JobID] - Completely purges a video from S3 and DynamoDB.
  • POST ?action=update_access&id=[JobID]&group=[Plan] - Locks video access to a specific subscription tier.

🤝 Contributing

Pull requests are welcome! If you encounter issues setting up the AWS resources or FFmpeg Lambda Layer, please submit an issue to the bug tracker.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streamvault_core_kaustubh-0.1.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

streamvault_core_kaustubh-0.1.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file streamvault_core_kaustubh-0.1.0.tar.gz.

File metadata

File hashes

Hashes for streamvault_core_kaustubh-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e8b25f7513b141e996b0bf9a419278106cb1350e20b429c81afee861bccad34c
MD5 907af089de714d95b2decb9f3ef8bf43
BLAKE2b-256 47f4585d594d71720f56db8aaba3c1fc4deea7fb662823ab14b257c0bf8fb9b0

See more details on using hashes here.

File details

Details for the file streamvault_core_kaustubh-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for streamvault_core_kaustubh-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4636ed37ebaea9d1d0fa640ee0fbd5334697e6d1d1e19269eb390bf10159f467
MD5 0a313a93eeb2e428b8bac35b405b8514
BLAKE2b-256 d673d7e1c5c5e932814eac3414fcfa6a40f88a08c3a0980ad06267faa0a770b3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page