🎥 Make videos programmatically with React
php
Jonny Burger1cb7a70ea2c8
diff --git a/packages/docs/docs/lambda/php.md b/packages/docs/docs/lambda/php.mdnew file mode 100644index 0000000000..17c331511d--- /dev/null+++ b/packages/docs/docs/lambda/php.md@@ -0,0 +1,411 @@+---+title: Triggering renders from PHP+slug: /lambda/php+sidebar_label: Rendering from PHP+crumb: "@remotion/lambda"+---++To trigger a Lambda render using PHP, you need to use the AWS SDK directly. Below you find a snippet showing the sample call to the AWS SDK. Note the following:++- You first need to [complete the Lambda setup](/docs/lambda/setup).+- Unstable API: The format that Remotion Lambda accepts can change in every version. You need to consult the [history of this page](https://github.com/remotion-dev/remotion/commits/main/packages/docs/docs/lambda/php/index.md) to see the changes over time. This page always shows the latest version of the payload.+- Sending large input props (>200KB) is not supported with PHP at the moment.++```php title="remotion.php"+<?php++// We'll assume you use Composer, which will add autoload.php+require_once __DIR__ . '/vendor/autoload.php';++use Aws\Lambda\LambdaClient;++<?php+++// Specify your environment variables in a .env file+$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);+$dotenv->load();++// Specify the region you deployed to, for example "us-east-1"+$region = $_ENV['REMOTION_APP_REGION'];+// Specify your S3 bucket name+$bucketName = $_ENV['REMOTION_APP_BUCKET'];+// Specify the function you would like to call+$functionName = $_ENV['REMOTION_APP_FUNCTION_NAME'];+// Specify the URL to your Webpack bundle+$serveUrl = $_ENV["REMOTION_APP_SERVE_URL"];++$credentials = null;++// If you don't have credentials but want to retrieve them using STS, use the AssumeRole feature+if ($_ENV["REMOTION_APP_IS_ASSUME_ROLE"] === true) {+ $credentials = assumeRole($_ENV["REMOTION_APP_REGION"],+ $_ENV["REMOTION_APP_ROLE_ARN"], $_ENV["REMOTION_APP_ROLE_SESSION_NAME"]);+}++$client = LambdaClient::factory([+ 'version' => 'latest',+ 'region' => $region,+ 'credentials' => $credentials,+]);++// Specify your input props here+$data = array("data" => "");+$input = serializeInputProps(+ $data,+ $region,+ "video-or-audio",+ null+);++// Note that the payload format may change in any version.+// This is the structure of the latest version.+$params = array(+ "serveUrl" => $serverUrl,+ "inputProps" => $input,+ "composition" => "main",+ "type" => "start",+ "codec" => "h264",+ // Specify the Remotion version you are using+ "version" => "3.3.82",+ "codec" => "h264",+ "imageFormat" => "jpeg",+ "crf" => null,+ "envVariables" => array(),+ "quality" => 80,+ "maxRetries" => 1,+ "privacy" => 'public',+ "logLevel" => 'info',+ "frameRange" => null,+ "outName" => null,+ "timeoutInMilliseconds" => 30000,+ "chromiumOptions" => array(),+ "scale" => 1,+ "everyNthFrame" => 1,+ "numberOfGifLoops" => 0,+ "concurrencyPerLambda" => 1,+ "downloadBehavior" => array(+ "type" => "play-in-browser",+ ),+ "muted" => false,+ "overwrite" => false,+ "audioBitrate" => null,+ "videoBitrate" => null,+ "webhook" => null,+ "forceHeight" => null,+ "forceWidth" => null,+ "bucketName" => null,+ "audioCodec" => null,+ "forceBucketName" => $bucketName,+);++try {+ // Invoke the Lambda function+ $result = $client->invoke([+ 'InvocationType' => 'RequestResponse',+ 'FunctionName' => $functionName,+ 'Payload' => json_encode($params),+ ]);++ $json_response = $result['Payload']->getContents();+ echo $json_response;+} catch (AwsException $e) {+ // Handle the exception+ echo $e->getMessage();+}++function serializeInputProps($inputProps, string $region, string $type, ?string $userSpecifiedBucketName): array+{+ try {+ $payload = json_encode($inputProps);+ $hash = randomHash();++ $MAX_INLINE_PAYLOAD_SIZE = 200000;++ if (strlen($payload) > $MAX_INLINE_PAYLOAD_SIZE) {++ throw new Exception(+ sprintf(+ "Warning: inputProps are over %dKB (%dKB) in size.\n This is not currently supported.",+ round($MAX_INLINE_PAYLOAD_SIZE / 1000),+ ceil(strlen($payload) / 1024)+ )++ );++ }++ return [+ 'type' => 'payload',+ 'payload' => $payload,+ ];+ } catch (Exception $e) {+ throw new Exception(+ 'Error serializing inputProps. Check it has no circular references or reduce the size if the object is big.'+ );+ }+}++function assumeRole($region, $ARN, $sessionName)+{++ try {+ $stsClient = new Aws\Sts\StsClient([+ 'region' => $region,+ 'version' => 'latest',+ ]);++ $result = $stsClient->AssumeRole([+ 'RoleArn' => $ARN,+ 'RoleSessionName' => $sessionName,+ ]);++ return [+ 'key' => $result['Credentials']['AccessKeyId'],+ 'secret' => $result['Credentials']['SecretAccessKey'],+ 'token' => $result['Credentials']['SessionToken'],+ ];+ } catch (AwsException $e) {+ // Handle the exception+ echo $e->getMessage();+ return null;+ }+}++```++## Reference applications++2 reference projects are available:++- [php-remotion](https://github.com/alexfernandez803/remotion-serverless/tree/main/php-remotion). This is an application that invokes the Remotion Lambda function containing the minimum parameters to render a video.+- [remotion-laravel](https://github.com/alexfernandez803/remotion-serverless/tree/main/remotion-laravel) is an application that serves a REST endpoint using [Laravel](https://laravel.com/) PHP framework. This endpoint invokes the Remotion lambda function with the necessary parameters to render a video.++Both use [remotion-app](https://github.com/alexfernandez803/remotion-serverless/tree/main/remotion-app), which includes a Remotion composition and utility scripts for deploying and deleting Remotion Lambda infrastructure in AWS.++### Bare PHP++Ensure that [remotion-app](https://github.com/alexfernandez803/remotion-serverless/tree/main/remotion-app) is already deployed on your AWS Account.++The [`php-remotion`](https://github.com/alexfernandez803/remotion-serverless/tree/main/php-remotion) application will call Remotion Lambda to render a video and contains the bare minimum parameters for Remotion's Lambda [arguments](https://www.remotion.dev/docs/lambda/rendermediaonlambda#arguments). Once the parameters are [constructed](https://github.com/alexfernandez803/remotion-serverless/blob/main/remotion-laravel/app/Services/RemotionService.php#L42), they will be passed on to the AWS Lambda Client using the [AWS PHP SDK](https://aws.amazon.com/sdk-for-php/). This project imitates the operation of [rendermediaonlambda](https://www.remotion.dev/docs/lambda/rendermediaonlambda) and uses [composer](https://gettcomposer.org/doc/01-basic-usage.md).++<p>+<Step>1</Step><strong> Clone or download the project</strong>+</p>++Clone the project using:++```bash+git clone https://github.com/alexfernandez803/php-remotion+```++<p>+<Step>2</Step><strong> Traverse to <code>remotion-serverless/php-remotion</code> </strong>+</p>++```bash+cd remotion-serverless && cd php-remotion+```++<p>+<Step>3</Step> <strong>Install dependencies using Composer</strong>+</p>++```bash+php composer.phar update+```++:::note+If you don't have [Composer](https://getcomposer.org/) installed, follow this [guide](https://getcomposer.org/doc/00-intro.md) to install it.+:::++<p>+<Step>4</Step> <strong>Configure environment variables</strong>+</p>++The application has a `.env` file that needs to be populated for the video render to work properly. An `.env.example` has been included in the project containing example values.++```bash title=".env"+REMOTION_APP_IS_ASSUME_ROLE="false"+REMOTION_APP_REGION="ap-southeast-2"+REMOTION_APP_BUCKET="remotionlambda-apsoutheast2-xxxxxx"+REMOTION_APP_FUNCTION_NAME="remotion-render-3-3-78-mem2048mb-disk2048mb-240sec"+REMOTION_APP_SERVE_URL="https://remotionlambda-apsoutheast2-qv16gcf02l.s3.ap-southeast-2.amazonaws.com/sites/remotion-render-app-3.3.78/index.html"+REMOTION_APP_ROLE_ARN="arn:aws:iam::123456789012:role/xaccounts3access"+REMOTION_APP_ROLE_SESSION_NAME="remotion_session_name"+```++- `REMOTION_APP_REGION` Is the AWS region you are using, e.g `us-east-1`.+- `REMOTION_APP_IS_ASSUME_ROLE` accepts either `true` or `false`. When set to `true` the application the application calls the AWS STS [`AssumeRole`](https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html) command, retrieve the `key`, `secret` and `token` and pass those credentials in `LambdaClient::factory`. Ensure that `REMOTION_APP_ROLE_ARN` and `REMOTION_APP_ROLE_SESSION_NAME` are provided when using this flag. This approach is appropriate if you want to deploy this application in AWS [EC2](https://aws.amazon.com/ec2/). Roles are required to be set up for the application. Please refer to the [Authenticating Lambda with EC2](/docs/lambda/ec2) guide and follow steps 1 to 4.++ ```bash title="Assume role"+ $credentials = NULL;+ if ($_ENV["REMOTION_APP_IS_ASSUME_ROLE"] === true) {+ $credentials = assumeRole($_ENV["REMOTION_APP_REGION"],+ $_ENV["REMOTION_APP_ROLE_ARN"], $_ENV["REMOTION_APP_ROLE_SESSION_NAME"]);+ }++ $client = LambdaClient::factory([+ 'version' => 'latest',+ 'region' => $region,+ 'credentials' => $credentials,+ ]);+ ```++The following variables can be retrieved by completing the Lambda [setup](/docs/lambda/setup):++- `REMOTION_APP_BUCKET` - Your bucket name+- `REMOTION_APP_FUNCTION_NAME` - The name of your deployed function. Note that it changes on every Remotion version.+- `REMOTION_APP_SERVE_URL` is where your Webpack bundle is hosted.++When you use Remotion on an AWS EC2 instance, set the following env variables. To set up the required roles, please refer to the [Authenticating Lambda with EC2](/docs/lambda/ec2) guide and follow steps `1` to `4`.++- `REMOTION_APP_ROLE_ARN` represents the ARN of the role which the application assume to render the video, for this instance it is `remotion-ec2-executionrole` ARN from `step 2` on this [guide](docs/lambda/ec2).+- `REMOTION_APP_ROLE_SESSION_NAME` a name to uniquely identify the role session when the same role is assumed by different principals.++<p>+<Step>5</Step> <strong>Running the application</strong>+</p>++Run the application by executing the command below:++```bash title="Run application"+php lambda-remotion-render.php+```++```bash title="Sample application response"+{"bucketName":"remotionlambda-apsoutheast2-xxxx","renderId":"b2xhi715yn"}+```++Once the execution is successful, the API will responsd with the `bucketName` and `renderId`. These are metadata required to get the status the video render or retrieving video.++### Laravel++This application can be executed on a local machine or computing instance, such as AWS EC2, to call Remotion Lambda and render a video. It includes the minimum parameters required for Remotion's Lambda [arguments](https://www.remotion.dev/docs/lambda/rendermediaonlambda#arguments) from a REST endpoint.++After [constructing](https://github.com/alexfernandez803/remotion-serverless/blob/main/remotion-laravel/app/Services/RemotionService.php#L42) the parameters, they will be passed on to the AWS Lambda Client using the [AWS PHP SDK](https://aws.amazon.com/sdk-for-php/). It also contains Laravel boilerplate code for setting up a REST endpoint that calls the Remotion Lambda. This project imitates the operation of [`renderMediaOnLambda()`](https://www.remotion.dev/docs/lambda/rendermediaonlambda) and uses [Composer](https://gettcomposer.org/doc/01-basic-usage.md).++<p>+<Step>1</Step><strong> Clone or download the project</strong>+</p>++```bash+git clone https://github.com/alexfernandez803/remotion-laravel+```++<p>+<Step>2</Step><strong> Traverse to <code>remotion-serverless/remotion-laravel</code> </strong>+</p>++```bash+cd remotion-serverless && cd remotion-laravel+```++<p>+<Step>3</Step> <strong>Install dependencies using Composer</strong>+</p>++```bash+php composer.phar update+```++<p>+<Step>4</Step> <strong>Setup environment variables</strong>+</p>++Refer to the bare PHP example for setting up the environment variables.++<p>+<Step>5</Step> <strong>Seed the database</strong>+</p>++The application requires a database, and for this application, [SQLite](<[SQLLite](https://sqlite.org/index.html)>) is used. Therefore, the configuration details from the `.env` file need to be provided.++```bash title=".env (continued)"+DB_CONNECTION=sqlite+DB_DATABASE=database.sqlite+```++- `DB_CONNECTION` is the connection type that represents which database to use ie, `MYSQL`+- `DB_DATABASE` is the database name, for this instance this represents the absolute URL path of the SQLite database.++Create the database and table in SQLite defined in `DB_DATABASE` by executing the command below:++```bash title="Create a database and table"+php artisan vendor:publish --tag=sanctum-migrations+```++<p>+<Step>6</Step> <strong>Running the application</strong>+</p>++Run the application by executing the command below:++```bash title="Run application"+php artisan serve+```++<p>+<Step>7</Step> <strong>Register with the application</strong>+</p>++```bash title="Send register request"+curl --location 'http://127.0.0.1:8000/api/register' \+ --header 'Content-Type: application/json' \+ --data-raw '{+ "name": "John Doe",+ "email": "[email protected]",+ "password": "L3tm3in@@",+ "confirm_password": "L3tm3in@@"+ }'+```++<p>+<Step>8</Step> <strong>Login to the application</strong>+</p>++```bash title="Log into the application"+curl --location 'http://127.0.0.1:8000/api/login' \+ --header 'Content-Type: application/json' \+ --data-raw '{+ "email": "[email protected]",+ "password": "L3tm3in@@"+ }'++```++```json title="Sample response"+{+ "success": true,+ "data": {+ "token": "2|ykXXPxXXX86pO4rXXXF49VhVXX34yGupU",+ "name": "John Doe"+ },+ "message": "User login successfully."+}+```++<p>+<Step>9</Step> <strong>Use token to render video</strong>+</p>++```bash title="Render video request"+curl --location --request POST 'http://127.0.0.1:8000/api/renders' \+ --header 'Authorization: Bearer 2|ykXXPxXXX86pO4rXXXF49VhVXX34yGupU'+```++```json title="Example response"+{+ "success": true,+ "data": {+ "bucketName": "remotionlambda-apsoutheast2-xxxxx",+ "renderId": "745b9itxb2"+ },+ "message": "Render Successful."+}+```++## See also++- [Using Lambda without IAM user](/docs/lambda/without-iam)+- [Permissions](/docs/lambda/permissions)diff --git a/packages/docs/docs/lambda/with-php/index.md b/packages/docs/docs/lambda/with-php/index.mddeleted file mode 100644index 754a504a70..0000000000--- a/packages/docs/docs/lambda/with-php/index.md+++ /dev/null@@ -1,129 +0,0 @@-----image: /generated/articles-docs-lambda-with-php-index.png-title: Using Remotion on standalone PHP application-slug: /lambda/remotion-standalone-php-sidebar_label: On standalone PHP application-crumb: "@remotion/lambda"------This guide demonstrate how to use Remotion with PHP in a standalone application.--To supplement this guide, two projects have been created.--- The [remotion-app](https://github.com/alexfernandez803/remotion-serverless/tree/main/remotion-app) includes a Remotion composition and utility scripts for deploying and deleting Remotion Lambda infrastructure in AWS. It should be noted that this is the same application as the one featured in the [Serverless Framework guide](/docs/lambda/serverless-framework-integration). Follow the setup [guide](/docs/lambda/serverless-framework-integration#remotion-app), if the Remotion lambda is not yet deployed to your AWS account.--- The [php-remotion](https://github.com/alexfernandez803/remotion-serverless/tree/main/php-remotion). This is an application that invokes the Remotion lambda function containing the minimum parameters to render a video.--### Prequisites--- Make sure that your local AWS profile is able to deploy to AWS, or follow this [guide](/docs/lambda/setup) to set up a user for your local machine.-- Ensure that [remotion-app](https://github.com/alexfernandez803/remotion-serverless/tree/main/remotion-app) is already deployed on your AWS Account.-- An understanding of [PHP](https://www.php.net/) language.-- Knowledge of how to use the [AWS PHP SDK](https://aws.amazon.com/sdk-for-php/) client is required.-- An understanding the use of [composer](https://gettcomposer.org/doc/01-basic-usage.md) in [PHP](https://www.php.net/). And this needs to be installed on your local machine.--## php-remotion--This is an application that can be executed on a local machine or computing instance like [AWS EC2](https://aws.amazon.com/ec2/). It will call Remotion Lambda to render a video and contains the bare minimum parameters for Remotion's lambda [arguments](https://www.remotion.dev/docs/lambda/rendermediaonlambda#arguments). Once the parameters are [constructed](https://github.com/alexfernandez803/remotion-serverless/blob/main/remotion-laravel/app/Services/RemotionService.php#L42), they will be passed on to the AWS Lambda Client using the [AWS PHP SDK](https://aws.amazon.com/sdk-for-php/). This project imitates the operation of [rendermediaonlambda](https://www.remotion.dev/docs/lambda/rendermediaonlambda) and uses [composer](https://gettcomposer.org/doc/01-basic-usage.md).---### Setup--#### 1. Clone or download the project--The project can be found at [`php-remotion`](https://github.com/alexfernandez803/php-remotion).-Clone the project using:--```bash-git clone https://github.com/alexfernandez803/php-remotion-```--#### 2. Go to `remotion-serverless` and traverse to `php-remotion` directory--```bash-cd remotion-serverless && cd php-remotion-```--#### 3. Install dependencies--```bash-php composer.phar update-```--:::note-If you don't have [composer](https://getcomposer.org/) installed, follow this [guide](https://getcomposer.org/doc/00-intro.md) to install in your local machine.-:::--#### 4. Configuring environment variables--The application has a `.env` file that needs to be populated for the video render to work properly. An `.env.example` has been included in the project containing example values.--```bash title=".env"-REMOTION_APP_IS_ASSUME_ROLE="false"-REMOTION_APP_REGION="ap-southeast-2"-REMOTION_APP_BUCKET="remotionlambda-apsoutheast2-xxxxxx"-REMOTION_APP_FUNCTION_NAME="remotion-render-3-3-78-mem2048mb-disk2048mb-240sec"-REMOTION_APP_SERVER_URL="https://remotionlambda-apsoutheast2-qv16gcf02l.s3.ap-southeast-2.amazonaws.com/sites/remotion-render-app-3.3.78/index.html"-REMOTION_APP_ROLE_ARN="arn:aws:iam::123456789012:role/xaccounts3access"-REMOTION_APP_ROLE_SESSION_NAME="remotion_session_name"-```--- `REMOTION_APP_REGION` this is where the Remotion Lambda function AWS region resides.-- `REMOTION_APP_IS_ASSUME_ROLE` accepts either `true` or `false`. This serves as a toggle to use AWS STS or use your AWS local credentials. When set to `true` the application the application calls the AWS STS [Assume Role](https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html) command, retrieve the `key`, `secret` and `token` and pass those credentials in `LambdaClient::factory`. Ensure that `REMOTION_APP_ROLE_ARN` and `REMOTION_APP_ROLE_SESSION_NAME` are provided when using the `assume role` functionality. This approach is appropriate if you want to deploy this application in AWS [EC2](https://aws.amazon.com/ec2/). Roles are required to be set up for the application. Please refer to the [Authenticating Lambda with EC2](/docs/lambda/ec2) guide and follow steps 1 to 4.-- ```bash title="assume role"-- $credential = NULL;- if ($_ENV["REMOTION_APP_IS_ASSUME_ROLE"] === true) {- $credential = assumeRole($_ENV["REMOTION_APP_REGION"],- $_ENV["REMOTION_APP_ROLE_ARN"], $_ENV["REMOTION_APP_ROLE_SESSION_NAME"]);- }-- $client = LambdaClient::factory([- 'version' => 'latest',- 'region' => $region,- 'credentials' => $credential,- ]);- ```-- The values for the `env` variables below can be found during the execution of the deployment of the [remotion-app](/docs/lambda/serverless-framework-integration#remotion-app). Please refer to the [Deploy the Lambda function section](/docs/lambda/serverless-framework-integration#5-deploy-the-lambda-function) for more information. Below is an example of the deployment logs:-- ```bash title="Deployment logs"-- Found 1 accounts. Deploying...- Ensured function="remotion-render-3-3-78-mem2048mb-disk2048mb-240sec" to region="ap-southeast-2" in account 1- entryPoint /xxxx/code/remotion-serverless/remotion-app/src/index.tsx- Deployed site to region="ap-southeast-2" in account 1 with bucket="remotionlambda-apsoutheast2-xxxxx" under serverUrl="https://remotionlambda-apsoutheast2-xxxxx.s3.ap-southeast-2.amazonaws.com/sites/remotion-render-app-3.3.78/index.html"- ```--- `REMOTION_APP_BUCKET` is an `S3` bucket where Remotion temporarily stores metadata and video during the render process. From the deployment logs it will be `remotionlambda-apsoutheast2-xxxxx`.-- `REMOTION_APP_FUNCTION_NAME` is the Remotion function name deployed in AWS, from the deployment logs it will be `remotion-render-3-3-78-mem2048mb-disk2048mb-240sec`.-- `REMOTION_APP_SERVER_URL` is where the remotion host all the compositions, from the deployment logs it will be `https://remotionlambda-apsoutheast2-xxxxx.s3.ap-southeast-2.amazonaws.com/sites/remotion-render-app-3.3.78/index.html`-- If you plan on using this application in an AWS EC2 instance, make sure to fill up the following env variables. To set up the required roles, please refer to the [Authenticating Lambda with EC2](/docs/lambda/ec2) guide and follow steps `1` to `4`.--- `REMOTION_APP_ROLE_ARN` represents the ARN of the role which the application assume to render the video, for this instance it is `remotion-ec2-executionrole` ARN from `step 2` on this [guide](docs/lambda/ec2).-- `REMOTION_APP_ROLE_SESSION_NAME` a name to uniquely identify the role session when the same role is assumed by different principals.--#### 5. Running the application--Run the application by executing the command below:--```bash title="Run application"-php lambda-remotion-render.php-```--```bash title="application response"-{"bucketName":"remotionlambda-apsoutheast2-xxxx","renderId":"b2xhi715yn"}-```--Once the execution is successful, the API will responsd with the `bucketName` and `renderId`. These are metadata required to get the status the video render or retrieving video.--## See also--- [Using Lambda without IAM user](/docs/lambda/without-iam)-- [Using Remotion on Laravel PHP Framework](/docs/lambda/with-php/laravel)-- [Using Lambda with SQS](/docs/lambda/sqs)-- [Permissions](/docs/lambda/permissions)-- [Serverless Framework](https://www.serverless.com/framework/docs/getting-started)-- Some codes are borrowed from [github-unwrapped-2021](https://github.com/remotion-dev/github-unwrapped-2021/tree/main/src)diff --git a/packages/docs/docs/lambda/with-php/laravel.md b/packages/docs/docs/lambda/with-php/laravel.mddeleted file mode 100644index 3bc38cf9b1..0000000000--- a/packages/docs/docs/lambda/with-php/laravel.md+++ /dev/null@@ -1,231 +0,0 @@-----image: /generated/articles-docs-lambda-with-php-laravel.png-title: Using Remotion on Laravel PHP Framework-slug: /lambda/remotion-laravel-php-sidebar_label: On Laravel PHP Framework-crumb: "@remotion/lambda"------This guide will show you how to use Remotion with a Laravel PHP application. Note that this setup is similar to [Using Remotion in PHP](/docs/lambda/with-php/index).--To supplement this guide, two projects have been created.--- The [remotion-app](https://github.com/alexfernandez803/remotion-serverless/tree/main/remotion-app) includes a Remotion composition and utility scripts for deploying and deleting Remotion Lambda infrastructure in AWS. It should be noted that this is the same application featured in the [Serverless Framework guide](/docs/lambda/serverless-framework-integration). If the Remotion Lambda has not yet been deployed to your AWS account, follow the setup [guide](/docs/lambda/serverless-framework-integration#remotion-app).--- The [remotion-laravel](https://github.com/alexfernandez803/remotion-serverless/tree/main/remotion-laravel) is an application that serves a REST endpoint using [Laravel](https://laravel.com/) PHP framework. This endpoint invokes the Remotion lambda function with the necessary parameters to render a video.--### Prequisites--- Make sure that your local AWS profile is able to deploy to AWS, or follow this [guide](/docs/lambda/setup) to set up a user for your local machine.-- Ensure that [remotion-app](https://github.com/alexfernandez803/remotion-serverless/tree/main/remotion-app) is already deployed on your AWS Account.-- An understanding the use of [composer](https://gettcomposer.org/doc/01-basic-usage.md) in [PHP](https://www.php.net/). And this needs to be installed on your local machine.-- An understanding of [PHP](https://www.php.net/) language.-- Knowledge of how to use the [AWS PHP SDK](https://aws.amazon.com/sdk-for-php/) client is required.-- Knowledge of development with [Laravel](https://laravel.com/) PHP framework--## remotion-laravel--This application can be executed on a local machine or computing instance, such as AWS EC2, to call Remotion Lambda and render a video. It includes the minimum parameters required for Remotion's lambda [arguments](https://www.remotion.dev/docs/lambda/rendermediaonlambda#arguments) from a REST endpoint. After [constructing](https://github.com/alexfernandez803/remotion-serverless/blob/main/remotion-laravel/app/Services/RemotionService.php#L42) the parameters, they will be passed on to the AWS Lambda Client using the [AWS PHP SDK](https://aws.amazon.com/sdk-for-php/). It also contains Laravel boilerplate code for setting up a REST endpoint that calls the Remotion Lambda. This project imitates the operation of [rendermediaonlambda](https://www.remotion.dev/docs/lambda/rendermediaonlambda) and uses [composer](https://gettcomposer.org/doc/01-basic-usage.md).---### Setup--#### 1. Clone or download the project--The project can be found at [`remotion-laravel`](https://github.com/alexfernandez803/remotion-laravel).-Clone the project using:--```bash-git clone https://github.com/alexfernandez803/remotion-laravel-```--#### 2. Go to `remotion-serverless` and traverse to `remotion-laravel` directory--```bash-cd remotion-serverless && cd remotion-laravel-```--#### 3. Install dependencies--```bash-php composer.phar update-```--:::note-If you don't have [composer](https://getcomposer.org/) installed, follow this [guide](https://getcomposer.org/doc/00-intro.md) to install in your local machine.-:::--#### 4. Configuring environment variables--The application has a `.env` file that needs to be populated for the video render to work properly. An `.env.example` has been included in the project containing example values.-- ```bash title=".env"- REMOTION_APP_IS_ASSUME_ROLE="false"- REMOTION_APP_REGION="ap-southeast-2"- REMOTION_APP_BUCKET="remotionlambda-apsoutheast2-xxxxxx"- REMOTION_APP_FUNCTION_NAME="remotion-render-3-3-78-mem2048mb-disk2048mb-240sec"- REMOTION_APP_SERVER_URL="https://remotionlambda-apsoutheast2-qv16gcf02l.s3.ap-southeast-2.amazonaws.com/sites/remotion-render-app-3.3.78/index.html"- REMOTION_APP_ROLE_ARN="arn:aws:iam::123456789012:role/xaccounts3access"- REMOTION_APP_ROLE_SESSION_NAME="remotion_session_name"- ```--- `REMOTION_APP_REGION` this is where the Remotion Lambda function AWS region resides.-- `REMOTION_APP_IS_ASSUME_ROLE` environment variable can accept either `true` or `false`. This serves as a toggle to use either AWS STS or your local AWS credentials. When set to `true`, the application calls the AWS STS [Assume Role](https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html) command, retrieves the `key`, `secret`, and `token`, and passes those credentials in `LambdaClient::factory`. Make sure that `REMOTION_APP_ROLE_ARN` and `REMOTION_APP_ROLE_SESSION_NAME` are provided when using the assume role functionality. This approach is appropriate if you want to deploy this application in AWS [EC2](https://aws.amazon.com/ec2/). Roles are required to be set up for the application. Please refer to the [Authenticating Lambda with EC2](/docs/lambda/ec2) guide and follow steps `1` to `4`.-- ```bash title="assume role"-- $credential = NULL;- if ($_ENV["REMOTION_APP_IS_ASSUME_ROLE"] === true) {- $credential = assumeRole($_ENV["REMOTION_APP_REGION"],- $_ENV["REMOTION_APP_ROLE_ARN"], $_ENV["REMOTION_APP_ROLE_SESSION_NAME"]);- }-- $client = LambdaClient::factory([- 'version' => 'latest',- 'region' => $region,- 'credentials' => $credential,- ]);- ```-- This code is extracted from [here](https://github.com/alexfernandez803/remotion-serverless/blob/main/remotion-laravel/app/Services/RemotionService.php#L24).-- The values for the `env` variables below can be found during the execution of the deployment of the [remotion-app](/docs/lambda/serverless-framework-integration#remotion-app). Please refer to the [Deploy the Lambda function section](/docs/lambda/serverless-framework-integration#5-deploy-the-lambda-function) for more information. Below is an example output of the deployment logs:-- ```bash title="Deployment logs"-- Found 1 accounts. Deploying...- Ensured function="remotion-render-3-3-78-mem2048mb-disk2048mb-240sec" to region="ap-southeast-2" in account 1- entryPoint /xxxx/code/remotion-serverless/remotion-app/src/index.tsx- Deployed site to region="ap-southeast-2" in account 1 with bucket="remotionlambda-apsoutheast2-xxxxx" under serverUrl="https://remotionlambda-apsoutheast2-xxxxx.s3.ap-southeast-2.amazonaws.com/sites/remotion-render-app-3.3.78/index.html"- ```--- `REMOTION_APP_BUCKET` is an `S3` bucket where Remotion temporarily stores metadata and video during the render process. From the deployment logs it will be `remotionlambda-apsoutheast2-xxxxx`.-- `REMOTION_APP_FUNCTION_NAME` is the Remotion function name deployed in AWS, from the deployment logs it will be `remotion-render-3-3-78-mem2048mb-disk2048mb-240sec`.-- `REMOTION_APP_SERVER_URL` is where the remotion host all the compositions, from the deployment logs it will be `https://remotionlambda-apsoutheast2-xxxxx.s3.ap-southeast-2.amazonaws.com/sites/remotion-render-app-3.3.78/index.html`-- If you plan on using this application in an AWS EC2 instance, make sure to fill up the following `env` variables `REMOTION_APP_ROLE_ARN` and `REMOTION_APP_ROLE_SESSION_NAME`. To setup the required roles and retrieve the value for `REMOTION_APP_ROLE_ARN`, please refer to the [Authenticating Lambda with EC2](/docs/lambda/ec2) guide and follow steps `1` to `4`.--- `REMOTION_APP_ROLE_ARN` represents the ARN of the role which the application assume to render the video, for this instance it is `remotion-ec2-executionrole` ARN from `step 2` on this [guide](docs/lambda/ec2).-- `REMOTION_APP_ROLE_SESSION_NAME` a name to uniquely identify the role session when the same role is assumed by different principals.--#### 5. Seed the database--The application requires a database, and for this application, [SQLite]([SQLLite](https://sqlite.org/index.html)) is used. Therefore, the configuration details from the `.env` file need to be provided.-- ```bash title=".env continued"- DB_CONNECTION=sqlite- DB_DATABASE=database.sqlite- ```- - `DB_CONNECTION` is the connection type that represents which database to use ie, `MYSQL`- - `DB_DATABASE` is the database name, for this instance this represents the absolute url path of the sqllte database.---Create the database and table in SQLLite defined in `DB_DATABASE` by executing the command below:--```bash title="create db and table"-php artisan vendor:publish --tag=sanctum-migrations-```---#### 6. Running the application--Run the application by executing the command below:--```bash title="Run application"-php artisan serve-```--```bash title="application logs"-INFO Server running on [http://127.0.0.1:8000].--Press Ctrl+C to stop the server-```-This application will setup a web server that serves a PHP REST endpoint accessible on port `8000`. It can be interacted with using an API client such as [curl](https://curl.se/) or [Postman](https://www.postman.com/).---### Interacting with the application--The application has an authentication and authorization mechanism in place, backed by a [SQLLite](https://sqlite.org/index.html) database located in the local directory. Below are the steps for interacting with the application.-- #### Steps- - <Step>1</Step> Register to the application-- ```bash title="register user"- curl --location 'http://127.0.0.1:8000/api/register' \- --header 'Content-Type: application/json' \- --data-raw '{- "name": "John Doe",- "email": "[email protected]",- "password": "L3tm3in@@",- "confirm_password": "L3tm3in@@"- }'- ```-- ```bash title="registration response"-{- "success": true,- "data": {- "token": "1|fcIPBALS7sXXXXyJhS3d59qcNEjpaICuqf1J",- "name": "John Doe"- },- "message": "User registered successfully."-}- ```-- - <Step>2</Step> Login to the application-- ```bash title="login request"- curl --location 'http://127.0.0.1:8000/api/login' \- --header 'Content-Type: application/json' \- --data-raw '{- "email": "[email protected]",- "password": "L3tm3in@@"- }'- ```-- ```bash title="login response"- {- "success": true,- "data": {- "token": "2|ykXXPxXXX86pO4rXXXF49VhVXX34yGupU",- "name": "John Doe"- },- "message": "User login successfully."- }- ```-- - <Step>3</Step> Use token to render video-- ```bash title="render video"- curl --location --request POST 'http://127.0.0.1:8000/api/renders' \- --header 'Authorization: Bearer 2|ykXXPxXXX86pO4rXXXF49VhVXX34yGupU'- ```-- ```bash title="render video response"- {- "success": true,- "data": {- "bucketName": "remotionlambda-apsoutheast2-xxxxx",- "renderId": "745b9itxb2"- },- "message": "Render Successful."- }- ```-- This API operation starts with the Laravel [controller](https://laravel.com/docs/10.x/controllers) called [RenderController.php](https://github.com/alexfernandez803/remotion-serverless/blob/main/remotion-laravel/app/Http/Controllers/RenderController.php) located in the application's directory. The [render](https://github.com/alexfernandez803/remotion-serverless/blob/main/remotion-laravel/app/Http/Controllers/RenderController.php#L24) function within the RenderController.php is executed. From there, the RemotionService [render](https://github.com/alexfernandez803/remotion-serverless/blob/main/remotion-laravel/app/Services/RemotionService.php#L10) function is executed, followed by the [renderOps](https://github.com/alexfernandez803/remotion-serverless/blob/main/remotion-laravel/app/Services/RemotionService.php#L16) function. The `renderOps` function constructs the arguments required by Remotion's lambda.--- Once the execution is successful, the API will respond with the `bucketName` and `renderId`. These are metadata required to get the status of the video render or retrieve the video.--### Resources-- [Implementing authentication on Laravel using sanctum](https://linuxhint.com/rest-api-authentication-laravel-sanctum/)-- [AWS PHP SDK](https://docs.aws.amazon.com/aws-sdk-php/v2/guide/service-lambda.html#factory-method)--## See also--- [Using Remotion on standalone application](/docs/lambda/with-php/index)-- [Using Lambda without IAM user](/docs/lambda/without-iam)-- [Using Lambda with SQS](/docs/lambda/sqs)-- [Permissions](/docs/lambda/permissions)-- [Serverless Framework](https://www.serverless.com/framework/docs/getting-started)-- Some codes are borrowed from [github-unwrapped-2021](https://github.com/remotion-dev/github-unwrapped-2021/tree/main/src)diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.jsindex 53ac1cb945..cf7c1e816b 100644--- a/packages/docs/sidebars.js+++ b/packages/docs/sidebars.js@@ -421,7 +421,6 @@ module.exports = {"lambda/custom-destination","lambda/checklist","lambda/webhooks",- "lambda/feb-2023-incident",{type: "category",label: "Troubleshooting",@@ -447,18 +446,7 @@ module.exports = {"lambda/without-iam/ec2",],},- {- type: "category",- label: "Remotion with PHP",- link: {- type: "doc",- id: "lambda/with-php/index",- },- items: [- "lambda/with-php/index",- "lambda/with-php/laravel",- ],- },+ "lambda/php","lambda/serverless-framework-integration","lambda/sqs","lambda/multiple-buckets",@@ -469,6 +457,7 @@ module.exports = {"lambda/changelog","lambda/upgrading","lambda/uninstall",+ "lambda/feb-2023-incident",],},{