Create a Serverless Video Thumbnail Extractor

By Pulumi Team
Published
Updated

The Challenge

You need to automatically process video files when they are uploaded, extracting thumbnails or frames without managing servers. This is a common requirement for media platforms, content management systems, or any application that needs to generate previews from video content.

What You'll Build

  • S3 buckets for video uploads and generated thumbnails
  • Container-based Lambda function with FFmpeg for video processing
  • Automatic S3 event triggers on video file upload
  • Thumbnail extraction and storage pipeline
  • Fully serverless with no infrastructure to manage

Neo Try This Prompt in Pulumi Neo

Run this prompt in Neo to deploy your infrastructure, or edit it to customize.

Best For

Use this prompt when you need automatic video processing triggered by file uploads. Ideal for media platforms, content management systems, video sharing applications, or any workflow that needs to generate thumbnails, extract frames, or process video files on upload.

Architecture Overview

This architecture creates an event-driven video processing pipeline using three core AWS services: S3 for storage, Lambda for compute, and ECR for container image management. When a video file is uploaded to the input S3 bucket, an event notification triggers a Lambda function that processes the video and saves the extracted thumbnail to an output bucket. The entire pipeline is serverless, scaling to handle concurrent uploads without any capacity planning.

The Lambda function runs as a container image rather than a ZIP-based deployment, which is essential for this use case because FFmpeg (the video processing tool) is a native binary that needs to be packaged with its dependencies. Container-based Lambda lets you include FFmpeg and any other system-level tools in a Docker image, then deploy it as a standard Lambda function with the same scaling and billing model.

The event-driven design means you do not need a polling mechanism or a message queue between the upload step and the processing step. S3 event notifications invoke Lambda directly when objects matching your filter criteria (like .mp4 file extensions) are created. This keeps the architecture simple and eliminates idle compute costs.

S3 Buckets

Two S3 buckets serve distinct roles in the pipeline. The input bucket receives video uploads and is configured with event notifications that trigger the Lambda function. The output bucket stores the generated thumbnails. Separating input and output into different buckets prevents accidental recursive triggers, where a Lambda function writing to the same bucket that triggers it could create an infinite loop.

Both buckets can be configured with lifecycle policies to manage storage costs. For example, you might move older thumbnails to S3 Infrequent Access or delete source videos after a retention period.

Container-Based Lambda Function

The Lambda function is packaged as a Docker image stored in ECR. The container image includes FFmpeg, your processing code, and any other dependencies. This approach avoids the size limitations of ZIP-based Lambda deployments and gives you full control over the runtime environment.

The function receives an S3 event payload containing the bucket name and object key for the uploaded video. It downloads the video from S3, runs FFmpeg to extract a frame at the desired timestamp, and uploads the resulting thumbnail image to the output bucket. The function’s timeout should be configured generously for video processing, since FFmpeg operations on large files can take several minutes.

S3 Event Notifications

S3 event notifications connect uploads to processing. You can filter notifications by prefix or suffix, so only video files (not thumbnails or metadata files) trigger the Lambda function. The notification configuration specifies the event type (object creation), the filter criteria, and the Lambda function ARN.

Lambda needs explicit permission to be invoked by S3 events. The deployment includes a resource-based policy on the Lambda function granting the S3 service permission to invoke it from the specific source bucket.

Common Customizations

  • Extract multiple thumbnails: Modify the Lambda function to extract frames at multiple timestamps and upload a gallery of thumbnails for each video.
  • Process additional formats: Extend the event notification filter to trigger on other video formats like .mov, .avi, or .webm.
  • Add SNS notifications: Send a notification when processing completes, informing downstream systems or users that thumbnails are ready.
  • Generate different output sizes: Modify the FFmpeg command to produce thumbnails at multiple resolutions for responsive image serving.