Skip to content

🎥 Make videos programmatically with React

lambda-python: Use auto-discovery bucket logic matching JS SDK

copilot-swe-agent[bot]97e77c971d97
diff --git a/packages/docs/docs/lambda/python.mdx b/packages/docs/docs/lambda/python.mdx
index fde7baabad..bd90cf06bb 100644
--- a/packages/docs/docs/lambda/python.mdx
+++ b/packages/docs/docs/lambda/python.mdx
@@ -16,7 +16,7 @@ You first need to [complete the Lambda setup](/docs/lambda/setup).
~~Sending large input props (>200KB) is not supported with Python at the moment.~~ _available from v4.0.315_
-Starting from v4.0.315, the Python SDK automatically handles large input props by uploading them to S3 when they exceed AWS Lambda payload limits. Props larger than 200KB for video renders and 5MB for still renders are automatically compressed using the same logic as the JavaScript SDK.
+Starting from v4.0.315, the Python SDK automatically handles large input props by uploading them to S3 when they exceed AWS Lambda payload limits. Props larger than 200KB for video renders and 5MB for still renders are automatically compressed using the same logic as the JavaScript SDK. The SDK will automatically find or create an appropriate S3 bucket following Remotion's naming conventions.
## Rendering a video
@@ -49,13 +49,6 @@ client = RemotionClient(region=REMOTION_APP_REGION,
serve_url=REMOTION_APP_SERVE_URL,
function_name=REMOTION_APP_FUNCTION_NAME)
-# For large input props, optionally specify a bucket name
-# If not specified, a bucket will be created automatically
-# client = RemotionClient(region=REMOTION_APP_REGION,
-# serve_url=REMOTION_APP_SERVE_URL,
-# function_name=REMOTION_APP_FUNCTION_NAME,
-# bucket_name="my-remotion-bucket")
-
# Set render request
render_params = RenderMediaParams(
composition="react-svg",
@@ -92,7 +85,7 @@ The Python SDK automatically handles large input props by uploading them to S3 w
- Video/audio renders: Props larger than ~194KB
- Still renders: Props larger than ~4.9MB
-When large props are detected, they are automatically uploaded to S3 and referenced by the Lambda function. This process is transparent to the user.
+When large props are detected, they are automatically uploaded to S3 and referenced by the Lambda function. The SDK will find an existing Remotion bucket or create a new one automatically, following the same logic as the JavaScript SDK. This process is transparent to the user.
```python title="large_props_example.py"
# Large input props are handled automatically
diff --git a/packages/lambda-python/remotion_lambda/remotionclient.py b/packages/lambda-python/remotion_lambda/remotionclient.py
index 051a3a1fd2..4bdae5462f 100644
--- a/packages/lambda-python/remotion_lambda/remotionclient.py
+++ b/packages/lambda-python/remotion_lambda/remotionclient.py
@@ -2,7 +2,6 @@
from dataclasses import asdict
import json
import hashlib
-import uuid
from math import ceil
from typing import Optional, Union
from enum import Enum
@@ -19,7 +18,7 @@ class RemotionClient:
# pylint: disable=too-many-arguments
def __init__(self, region, serve_url, function_name, access_key=None, secret_key=None,
- bucket_name=None, force_path_style=False):
+ force_path_style=False):
"""
Initialize the RemotionClient.
@@ -29,7 +28,6 @@ class RemotionClient:
function_name (str): Name of the AWS Lambda function.
access_key (str): AWS access key (optional).
secret_key (str): AWS secret key (optional).
- bucket_name (str): S3 bucket name for large payloads (optional).
force_path_style (bool): Force path-style S3 URLs (optional).
"""
self.access_key = access_key
@@ -37,7 +35,6 @@ class RemotionClient:
self.region = region
self.serve_url = serve_url
self.function_name = function_name
- self.bucket_name = bucket_name
self.force_path_style = force_path_style
def _generate_hash(self, payload):
@@ -46,12 +43,17 @@ class RemotionClient:
def _generate_random_hash(self):
"""Generate a random hash for bucket operations."""
- return uuid.uuid4().hex
+ import random
+ import string
+ alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789'
+ return ''.join(random.choice(alphabet) for _ in range(10))
def _make_bucket_name(self):
"""Generate a bucket name following Remotion conventions."""
- random_suffix = self._generate_random_hash()[:8]
- return f"remotion-render-{self.region}-{random_suffix}"
+ # Use the same logic as JS SDK: prefix + region without dashes + random hash
+ region_no_dashes = self.region.replace('-', '')
+ random_suffix = self._generate_random_hash()
+ return f"remotionlambda-{region_no_dashes}-{random_suffix}"
def _input_props_key(self, hash_value):
"""Generate S3 key for input props."""
@@ -79,7 +81,7 @@ class RemotionClient:
buckets = []
for bucket in response['Buckets']:
bucket_name = bucket['Name']
- if bucket_name.startswith('remotion-render-'):
+ if bucket_name.startswith('remotionlambda-'):
# Check if bucket is in the correct region
try:
bucket_region = s3_client.get_bucket_location(Bucket=bucket_name)
@@ -95,18 +97,18 @@ class RemotionClient:
return []
def _get_or_create_bucket(self):
- """Get existing bucket or create a new one."""
- if self.bucket_name:
- return self.bucket_name
-
+ """Get existing bucket or create a new one following JS SDK logic."""
buckets = self._get_remotion_buckets()
+
if len(buckets) > 1:
raise ValueError(
f"You have multiple buckets ({', '.join(buckets)}) in your S3 region "
- f"({self.region}) starting with 'remotion-render-'. Please specify a bucket_name."
+ f"({self.region}) starting with \"remotionlambda-\". "
+ "Please see https://remotion.dev/docs/lambda/multiple-buckets."
)
if len(buckets) == 1:
+ # Use existing bucket - in JS SDK this also applies lifecycle rules
return buckets[0]
# Create new bucket
diff --git a/packages/lambda-python/tests/test_large_payload_compression.py b/packages/lambda-python/tests/test_large_payload_compression.py
index 95c9b85011..8f8fcd8782 100644
--- a/packages/lambda-python/tests/test_large_payload_compression.py
+++ b/packages/lambda-python/tests/test_large_payload_compression.py
@@ -10,8 +10,7 @@ class TestLargePayloadCompression(unittest.TestCase):
self.client = RemotionClient(
region="us-east-1",
serve_url="testbed",
- function_name="remotion-render",
- bucket_name="test-bucket"
+ function_name="remotion-render"
)
def test_small_payload_uses_payload_format(self):
@@ -28,7 +27,7 @@ class TestLargePayloadCompression(unittest.TestCase):
@patch('remotion_lambda.remotionclient.RemotionClient._get_or_create_bucket')
def test_large_payload_uses_bucket_format(self, mock_get_bucket, mock_upload):
"""Test that large payloads use the bucket-url format."""
- mock_get_bucket.return_value = 'test-bucket'
+ mock_get_bucket.return_value = 'remotionlambda-useast1-testbucket'
# Create a large payload that exceeds the limit for video-or-audio (200KB - margin)
large_data = 'x' * 200000 # 200KB of data
@@ -39,7 +38,7 @@ class TestLargePayloadCompression(unittest.TestCase):
self.assertEqual(result['type'], 'bucket-url')
self.assertIn('hash', result)
self.assertIn('bucketName', result)
- self.assertEqual(result['bucketName'], 'test-bucket')
+ self.assertEqual(result['bucketName'], 'remotionlambda-useast1-testbucket')
# Verify S3 upload was called
mock_upload.assert_called_once()
@@ -74,6 +73,37 @@ class TestLargePayloadCompression(unittest.TestCase):
hash_value = 'test123'
key = self.client._input_props_key(hash_value)
self.assertEqual(key, 'input-props/test123.json')
+
+ def test_bucket_name_generation(self):
+ """Test bucket name generation following JS SDK conventions."""
+ bucket_name = self.client._make_bucket_name()
+
+ # Should start with remotionlambda- prefix
+ self.assertTrue(bucket_name.startswith('remotionlambda-'))
+
+ # Should contain region without dashes
+ expected_region = self.client.region.replace('-', '')
+ self.assertIn(expected_region, bucket_name)
+
+ # Should be in format: remotionlambda-{region-no-dashes}-{random-hash}
+ parts = bucket_name.split('-')
+ self.assertEqual(len(parts), 3) # remotionlambda, region, hash
+ self.assertEqual(parts[0], 'remotionlambda')
+ self.assertEqual(parts[1], expected_region)
+ self.assertEqual(len(parts[2]), 10) # random hash should be 10 chars
+
+ @patch('remotion_lambda.remotionclient.RemotionClient._get_remotion_buckets')
+ def test_get_or_create_bucket_with_multiple_buckets_raises_error(self, mock_get_buckets):
+ """Test that multiple buckets raises the correct error."""
+ mock_get_buckets.return_value = ['remotionlambda-useast1-abc123', 'remotionlambda-useast1-def456']
+
+ with self.assertRaises(ValueError) as context:
+ self.client._get_or_create_bucket()
+
+ error_message = str(context.exception)
+ self.assertIn('multiple buckets', error_message)
+ self.assertIn('remotionlambda-', error_message)
+ self.assertIn('https://remotion.dev/docs/lambda/multiple-buckets', error_message)
if __name__ == '__main__':