Skip to content

🎥 Make videos programmatically with React

update steps

Alex Fernandez1dfff9212c12
diff --git a/packages/docs/docs/lambda/ec2.md b/packages/docs/docs/lambda/ec2.md
index 551bf20887..5121e1d7ee 100644
--- a/packages/docs/docs/lambda/ec2.md
+++ b/packages/docs/docs/lambda/ec2.md
@@ -1,7 +1,7 @@
---
-title: Using Lambda with EC2
+title: Lambda render from EC2
slug: /lambda/ec2
-sidebar_label: Lambda rendering from ec2
+sidebar_label: Lambda render from EC2
crumb: "@remotion/lambda"
---
@@ -9,7 +9,7 @@ This guide will demonstrate how to securely interact with Remotion's [renderMedi
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).
+- 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 still not deployed your AWS account.
- The [ec2-remotion-lambda](https://github.com/alexfernandez803/remotion-serverless/tree/main/ec2-remotion-lambda) is a TypeScript Node.js application that initiates a video rendering process via a REST endpoint.
@@ -18,10 +18,10 @@ To supplement this guide, two projects have been created:
- AWS deployment profile on your local machine, to configure an AWS deployment profile on your local machine.
- A AWS policy created named `remotion-executionrole-policy` which is created from this [guide](/docs/lambda/without-iam/#1-create-role-policy).
- An understanding how [IAM](https://docs.aws.amazon.com/iam/index.html) and [assume role](https://docs.aws.amazon.com/IAM/latest/UserGuide/example_sts_AssumeRole_section.html) works in AWS.
-- A knowledge of creating and provisioning EC2 instances and installing packages in [Ubuntu distro](https://ubuntu.com/). These includes [Git](https://git-scm.com/), [NodeJs](https://nodejs.org/en), as well as running the nodejs application.
+- A knowledge of creating and provisioning EC2 instances and installing packages in [Ubuntu distro](https://ubuntu.com/). These includes [Git](https://git-scm.com/), [NodeJs](https://nodejs.org/en), as youll as running the nodejs application.
-### Setup
+### Setup for `ec2-remotion-lambda` application
#### 1. Create the Remotion policy
@@ -29,32 +29,33 @@ To supplement this guide, two projects have been created:
#### 2. Create role for remotion render execution
##### Steps
- - Go to the IAM Roles section of your AWS account.
- - Click "Create role".
- - Under "Select type of trusted entity", select "AWS service", and under "Choose the service that will use this role", select "Lambda". Click "Next: Permissions".
- - Under "Attach permissions policies", search for remotion-executionrole-policy and click the checkbox to assign this policy. If the policy has not been created, refer to step 1.
- - Additionally, still in "Attach permissions policies", clear the filter and search for AWSLambdaBasicExecutionRole. Click the checkbox and click "Next: Tags".
- - On the "Add tags" page, you can optionally add tags to the role. Click "Next: Review".
- - On the "Review" page, name the role remotion-lambda-role exactly. Leave the other fields as they are.
- - Click "Create role" to confirm.
+ - <Step>1</Step>Go to the IAM Roles section of your AWS account.
+ - <Step>2</Step>Click "Create role".
+ - <Step>3</Step>Under "Select type of trusted entity", select "AWS service", and under "Choose the service that will use this role", select "Lambda". Click "Next: Permissions".
+ - <Step>4</Step>Under "Attach permissions policies", search for "remotion-executionrole-policy" and click the checkbox to assign this policy. If the policy has not been created, refer to step 1.
+ - <Step>5</Step>Additionally, still in "Attach permissions policies", clear the filter and search for AWSLambdaBasicExecutionRole. Click the checkbox and click "Next: Tags".
+ - <Step>6</Step>On the "Add tags" page, you can optionally add tags to the role. Click "Next: Review".
+ - <Step>7</Step>On the "Review" page, name the role "remotion-lambda-role" exactly. Leave the other fields as they are.
+ - <Step>8</Step>Click "Create role" to confirm.
#### 3. Create a role for the EC2 instance
##### Steps
- - Go to the IAM Roles section of your AWS account.
- - Click "Create role".
- - Under "Select type of trusted entity", select "AWS service", and under "Choose the service that will use this role", select "EC2". Click "Next: Permissions".
- - Under "Attach permissions policies", leave it empty for now. Click "Next: Tags".
- - On the "Add tags" page, you can optionally add tags to the role. Click "Next: Review".
- - On the "Review" page, name the role ec2-remotion-role exactly. Leave the other fields as they are.
- - Click "Create role" to confirm.
- - Make a note of the ARN for the role.
+ - <Step>1</Step>Go to the IAM Roles section of your AWS account.
+ - <Step>2</Step>Click "Create role".
+ - <Step>3</Step>Under "Select type of trusted entity", select "AWS service", and under "Choose the service that will use this role", select "EC2". Click "Next: Permissions".
+ - <Step>4</Step>Under "Attach permissions policies", leave it empty for now. Click "Next: Tags".
+ - <Step>5</Step>On the "Add tags" page, you can optionally add tags to the role. Click "Next: Review".
+ - <Step>6</Step>On the "Review" page, name the role "ec2-remotion-role" exactly. Leave the other fields as they are.
+ - <Step>7</Step>Click "Create role" to confirm.
+ - <Step>8</Step>Make a note of the ARN for the role.
#### 4. Trust the ec2 role from remotion role
##### Steps
-- From IAM roles section again
- - Find the role from step 2, or filter roles by name using `remotion-lambda-role`. Keep the `ARN` of the role from step 3 handy.
- - From the trust relationship tab, click the "Edit trust policy" button.
- - Edit the policy statement and add the `ARN` of EC2 role(`ec2-remotion-role`) from step 3. It should added as one of the principal, as an `AWS` principal since it is a role.
+ - <Step>1</Step>From the IAM Roles section, find the role created in step 2, or filter roles by name using "remotion-lambda-role". Keep the "ARN" of this role handy.
+ - <Step>2</Step>Click on the role to open its details page.
+ - <Step>3</Step>From the "Trust relationships" tab, click the "Edit trust relationship" button.
+ - <Step>4</Step>Edit the policy statement to add the ARN of the EC2 role (ec2-remotion-role) created in step 3. Add it as one of the principals, as an AWS principal since it is a role.
+ - <Step>5</Step>Save the changes to the trust policy.
#### Example
```json
@@ -73,36 +74,43 @@ To supplement this guide, two projects have been created:
}
```
:::info
-This instructs `remotion-lambda-role` to allow `ec2-remotion-role` to assume its role with associated permission to access AWS services/resources that `remotion` needs to render videos.
+This configuration allows `ec2-remotion-role` to assume the role of `remotion-lambda-role` with the associated permissions to access AWS services and resources needed by Remotion to render videos.
:::
#### 4. Create the ec2 instance
- From AWS Management console.
- - Go to the EC2 dashboard by selecting EC2 from the list of services.
- - Click on the "Launch Instance" button.
- - Choose an Amazon Machine Image (AMI) that you want to use for your instance. You can select from a variety of pre-configured AMIs, or you can create your own. For this instance chose Ubuntu AMI.
- - Select an instance type that you want to use for your instance. The instance type determines the amount of CPU, memory, storage, and networking capacity that your instance will have.
- - Configure your instance details, such as the number of instances you want to launch, the VPC and subnet you want to use, and any advanced settings you want to enable.
- - From "Network setting" tick the "Allow SSH traffic from", and from selection of allowing access select "My IP address". This will allow you to connect to the server instance via SSH and SFTP to upload the dependencies.
- - From "Network setting" also, click "Allow HTTP traffic from the internet", this will allow the application to be trigger for REST API operation.
- - Add storage to your instance by selecting the storage type and size you want to use.
- - From "Advance details", on "IAM instance profile" find the role we specifically created for EC2 named "ec2-remotion-role". This gives access to the EC2 instance to assume the role for remotion.
- - Review your instance launch details and click the "Launch" button.
- - Choose an existing key pair or create a new key pair to securely connect to your instance. This key pair is necessary to access your instance via SSH.
- - Launch your instance by clicking the "Launch Instances" button.
- - Wait for your instance to launch. Once it's ready, you can connect to it using SSH, RDP, or other remote access methods.
+ - <Step>1</Step>Go to the EC2 dashboard by selecting EC2 from the list of services.
+ - <Step>2</Step>Click on the "Launch Instance" button.
+ - <Step>3</Step>Choose an Amazon Machine Image (AMI) that you want to use for your instance. You can select from a variety of pre-configured AMIs, or you can create your own. For this instance chose Ubuntu AMI.
+ - <Step>4</Step>Select an instance type that you want to use for your instance. The instance type determines the amount of CPU, memory, storage, and networking capacity that your instance will have.
+ - <Step>5</Step>Configure your instance details, such as the number of instances you want to launch, the VPC and subnet you want to use, and any advanced settings you want to enable.
+ - <Step>6</Step>From "Network setting" tick the "Allow SSH traffic from", and from selection of allowing access select "My IP address". This will allow you to connect to the server instance via SSH and SFTP to upload the dependencies.
+ - <Step>7</Step>From "Network setting" also, click "Allow HTTP traffic from the internet", this will allow the application to be trigger for REST API operation.
+ - <Step>8</Step>Add storage to your instance by selecting the storage type and size you want to use.
+ - <Step>9</Step>From "Advance details", on "IAM instance profile" find the role you specifically created for EC2 named "ec2-remotion-role". This gives access to the EC2 instance to assume the role for remotion.
+ - <Step>10</Step>Review your instance launch details and click the "Launch" button.
+ - <Step>11</Step>Choose an existing key pair or create a new key pair to securely connect to your instance. This key pair is necessary to access your instance via SSH.
+ - <Step>12</Step>Launch your instance by clicking the "Launch Instances" button.
+ - <Step>13</Step>Wait for your instance to launch. Once it's ready, you can connect to it using SSH, RDP, or other remote access methods.
#### 5. Upload the code to the server and install dependencies
+
+ - The application requires Node.js , to install Node.js and NPM on the server, you can follow this [guide](https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-20-04). Make sure the version of node is `v18.15.0`, you can use [NVM](https://github.com/nvm-sh/nvm) to easily switch Node.js version. You can install this by following this [guide](https://blog.logrocket.com/how-switch-node-js-versions-nvm/).
-Upload the application [code](https://github.com/alexfernandez803/remotion-serverless/tree/main/ec2-remotion-lambda) into the EC2 instance by any means that you are comfortable, for this instance we are uploading a SFTP client named [cyberduck(https://cyberduck.io/).
+ - Upload the application [code](https://github.com/alexfernandez803/remotion-serverless/tree/main/ec2-remotion-lambda) into the EC2 instance by any means that you are comfortable, for this instance the code is uploaded using SFTP client named [cyberduck](https://cyberduck.io/).
-- Go to the application directory
-- Execute the following command to install application dependency
-
-```bash
-npm i
-```
+ - Connect to the server using ssh client, below is an example how to connect to the server
+
+ ```
+ ssh -i "remotion.pem" [email protected]
+ ```
+ - Go to the application directory, and execute the following command to install application dependency.
+
+ ```bash
+ cd ~/ec2-remotion-lambda
+ npm i
+ ```
#### 6. Configure the application environment variables
@@ -127,7 +135,7 @@ npm i
#### 6. Run the application from the application directory
- ```bash
+ ```
npm run start
```
@@ -136,28 +144,26 @@ npm i
### Interacting with the application
The application can be interacted using CURL or Postman, to interact with the API follow the steps below.
-- Since the application is still not a daemon process, we need to launch another shell session connecting to the server.
- ```bash
- ssh blablah
+ - Since the application is still not a daemon process, you need to launch another shell session connecting to the server.
+ ```
+ ssh -i "remotion.pem" [email protected]
+ ```
+ - Execute the CURL command
+ ```title=Request
+ curl --location --request POST 'http://localhost:8080/render' \
+ --header 'Authorization: Basic YWRtaW46cGFzc3dvcmQ='
```
-- Execute the CURL command
-
-
- ```bash title=Request
-curl --location --request POST 'http://localhost:8080/render' \
---header 'Authorization: Basic YWRtaW46cGFzc3dvcmQ='
- ```
The `Authorization` header is a combination of word `Basic` and a space, then the `base64` encoded username and password joined together by colon, `username:password`.
From the `/render` API resource, the application will execute this piece of [code](https://github.com/alexfernandez803/remotion-serverless/blob/main/ec2-remotion-lambda/src/services/render-services.ts#L11) This codes assume the role of `ec2-remotion-role`, then provided with temporary access tokens ie `AccessKeyId`, `SecretAccessKey` and `SessionToken`. These credentials will then need to be set as environment variables on the server so that in can be used by the [`renderMediaOnLambda()`](/docs/lambda/rendermediaonlambda) process. Setting the environment parameters route the render process in this (code)[https://github.com/alexfernandez803/remotion-serverless/blob/main/ec2-app/render_handler.ts#L14].
- ```bash title=application logs
+ ```title=application logs
```
For testing, logs marker are added for identifying issues.
- ```bash title=API Response
+ ```title=API Response
```