🎥 Make videos programmatically with React
initial invoke
Alex Fernandez1e28c84fb770
diff --git a/packages/lambda-python/src/remotionclient.py b/packages/lambda-python/src/remotionclient.pyindex 043ad9d73c..44543fe8e3 100644--- a/packages/lambda-python/src/remotionclient.py+++ b/packages/lambda-python/src/remotionclient.py@@ -1,3 +1,4 @@+from math import ceilimport boto3import jsonfrom renderparams import RenderParams@@ -5,7 +6,7 @@ from renderparams import RenderParamsclass RemotionClient:- def __init__(self, region, serve_url, function_name=None, access_key=None, secret_key=None, session=None, ):+ def __init__(self, region, serve_url, function_name, access_key=None, secret_key=None, session=None, ):self.access_key = access_keyself.secret_key = secret_keyself.region = region@@ -14,6 +15,28 @@ class RemotionClient:self.session = sessionself.client = self.create_lambda_client()+ def serializeInputProps(self, inputProps, region, type, userSpecifiedBucketName):+ try:+ payload = json.dumps(inputProps)+ MAX_INLINE_PAYLOAD_SIZE = 5000000 if type == 'still' else 200000++ if len(payload) > MAX_INLINE_PAYLOAD_SIZE:+ raise Exception(+ "Warning: inputProps are over {}KB ({}KB) in size.\nThis is not currently supported.".format(+ round(MAX_INLINE_PAYLOAD_SIZE / 1000),+ ceil(len(payload) / 1024)+ )+ )++ return {+ 'type': 'payload',+ 'payload': payload if payload is not None and payload != '' and payload != "null" else json.dumps({})+ }+ except Exception as e:+ raise Exception(+ 'Error serializing inputProps. Check it has no circular references or reduce the size if the object is big.'+ )+def create_lambda_client(self):if self.session:return self.session.client('lambda', region_name=self.region)@@ -39,12 +62,19 @@ class RemotionClient:except Exception as e:print(f"Failed to invoke Lambda function: {str(e)}")- def contruct_request(self, render_params: RenderParams):+ def contruct_render_request(self, render_params: RenderParams):render_params.serveUrl = self.serve_urlrender_params.region = self.region+ render_params.function_name = self.function_name+ render_params.inputProps = self.serializeInputProps(+ inputProps=render_params.data,+ region=self.region,+ type="video-or-audio",+ userSpecifiedBucketName=None)return json.dumps(render_params.serializeParams())- # Function bodydef render_media_on_lambda(self, render_params: RenderParams):- print(render_params.serializeParams())- # Function body+ params = json.dumps(render_params.serializeParams())+ self.invoke_lambda(function_name=self.function_name,+ payload=params)+ # print(render_params.serializeParams())diff --git a/packages/lambda-python/src/test_client_with_unittest.py b/packages/lambda-python/src/test_client_with_unittest.pyindex 1b2394f08b..b7bc102738 100644--- a/packages/lambda-python/src/test_client_with_unittest.py+++ b/packages/lambda-python/src/test_client_with_unittest.py@@ -25,7 +25,7 @@ class TestRemotionClient(TestCase):},) # Instantiate a RenderParams object# Pass the object to renderMediaOnLambda- print(client.contruct_request(render_params))+ print(client.contruct_render_request(render_params))self.assertEqual(client.region, "us-east-1")self.assertIsNotNone(render_params)self.assertIsNotNone(render_params.data)diff --git a/packages/lambda-python/src/testclient.py b/packages/lambda-python/src/testclient.pynew file mode 100644index 0000000000..c320a0e70d--- /dev/null+++ b/packages/lambda-python/src/testclient.py@@ -0,0 +1,36 @@++from renderparams import RenderParams+from remotionclient import RemotionClient+import os+from dotenv import load_dotenv+++load_dotenv()++# environment variables defined inside a .env file+REMOTION_APP_REGION = "ap-southeast-2"+REMOTION_APP_BUCKET = "remotionlambda-apsoutheast2-qv16gcf02l"+REMOTION_APP_FUNCTION_NAME = "remotion-render-3-3-101-mem2048mb-disk2048mb-240sec"+REMOTION_APP_SERVE_URL = "https://remotionlambda-apsoutheast2-qv16gcf02l.s3.ap-southeast-2.amazonaws.com/sites/remotion-render-app-3.3.101/index.html"+++REMOTION_APP_REGION = os.getenv('REMOTION_APP_REGION')+REMOTION_APP_BUCKET = os.getenv('REMOTION_APP_BUCKET')+REMOTION_APP_FUNCTION_NAME = os.getenv('REMOTION_APP_FUNCTION_NAME')+REMOTION_APP_SERVE_URL = os.getenv('REMOTION_APP_SERVE_URL')+++client = RemotionClient(region=REMOTION_APP_REGION,+ serve_url=REMOTION_APP_SERVE_URL,+ function_name=REMOTION_APP_FUNCTION_NAME)++render_params = RenderParams(+ composition="main",+ data={+ 'hi': 'there'+ },+) # Instantiate a RenderParams object+# Pass the object to renderMediaOnLambda+print(client.contruct_render_request(render_params))+print("\n")+client.render_media_on_lambda(render_params)diff --git a/packages/lambda-python/src/version.py b/packages/lambda-python/src/version.pyindex da4d80bd33..96c7f11b67 100644--- a/packages/lambda-python/src/version.py+++ b/packages/lambda-python/src/version.py@@ -1,2 +1,2 @@-VERSION = "4.0.4"+VERSION = "4.0.0"# pylint: disable-all