Using Remotion Lambda with R2
R2 by Cloudflare is a popular way to store renders because there are no egress fees.
Create a Cloudflare bucket and set up an API key with Object Read & Write permissions.
Use an s3OutputProvider to store the rendered video in R2:
const {bucketName , renderId , cloudWatchMainLogs } = await renderMediaOnLambda ({
serveUrl : 'https://remotion-helloworld.vercel.app',
// FIXME: Add your function specs here
functionName : speculateFunctionName ({
diskSizeInMb : 2048,
memorySizeInMb : 2048,
timeoutInSeconds : 120,
}),
composition : 'HelloWorld',
region : 'eu-central-1',
codec : 'h264',
outName : {
// FIXME: Use the bucket name from your Cloudflare Storage settings
bucketName : 'remotion-test-bucket',
key : 'out.mp4',
s3OutputProvider : {
// FIXME: Use the endpoint from your Cloudflare Storage settings
endpoint : 'https://2fe488b3b0f4deee223aef7464784c46.r2.cloudflarestorage.com',
// FIXME: Use the Access Key from your Cloudflare settings
accessKeyId : process .env .R2_ACCESS_KEY_ID ?? '',
// FIXME: Use the Secret Access Key from your Cloudflare settings
secretAccessKey : process .env .R2_SECRET_ACCESS_KEY ?? '',
},
},
});Storing the site and assets in R2
Many Remotion users store their bundle and any assets such as input videos in R2, in order to avoid S3 bandwidth costs.
If you store input videos or audio files in R2, serve them through a custom domain with Cloudflare Cache enabled and configure a Cache Rule for those URLs.
This can reduce slow cold range requests when using @remotion/media, and the r2.dev development URL does not support caching.