AWS Lambda: download YouTube, TikTok and Instagram videos
Lambda + S3 is a common pattern for archiving video: the function resolves the URL with CrawlFetch and streams the file into a bucket.
How it fits together
An event (API Gateway, SQS or a schedule) triggers the function; it resolves the URL and uploads the stream to S3 with the SDK's multipart Upload helper.
AWS Lambda example
import { S3Client } from "@aws-sdk/client-s3";import { Upload } from "@aws-sdk/lib-storage";import { Readable } from "node:stream";const s3 = new S3Client({});export const handler = async (event) => {const r = await fetch("https://api.crawlfetch.com/v1/resolve?" + new URLSearchParams({ url: event.url }), {headers: { Authorization: "Bearer " + process.env.CRAWLFETCH_KEY },});if (!r.ok) throw new Error("resolve failed " + r.status);const video = await r.json();const file = await fetch(video.downloadUrl);await new Upload({client: s3,params: { Bucket: process.env.BUCKET, Key: "videos/" + video.id + ".mp4", Body: Readable.fromWeb(file.body) },}).done();return { id: video.id, title: video.title };};
Notes for AWS Lambda
- Keep the key in Secrets Manager or SSM Parameter Store.
- Feed URLs through SQS with a concurrency limit to respect your plan's rate limit.
- Running yt-dlp in Lambda often fails on datacenter IPs — see yt-dlp on cloud servers.
FAQ
Will long videos time out?
Lambda allows up to 15 minutes; for very long videos use Fargate or a worker instead.
Related
Last updated 2026-10-25