Skip to content

πŸŽ₯ Make videos programmatically with React

restructure doc

Jonny Burgerc44f96345441
diff --git a/packages/docs/docs/lambda/examplesetupwithoutiamuser.md b/packages/docs/docs/lambda/without-iam/example.md
similarity index 91%
rename from packages/docs/docs/lambda/examplesetupwithoutiamuser.md
rename to packages/docs/docs/lambda/without-iam/example.md
index 47e714bcf4..8880f8d136 100644
--- a/packages/docs/docs/lambda/examplesetupwithoutiamuser.md
+++ b/packages/docs/docs/lambda/without-iam/example.md
@@ -1,21 +1,22 @@
---
-image: /generated/articles-docs-lambda-examplesetupwithoutiamuser.png
-id: examplesetupwithoutiamuser
+image: /generated/articles-docs-lambda-without-iam-example.png
title: Example setup without IAM user
-slug: /lambda/example-setup-without-iam-user
-crumb: "Lambda"
+crumb: "Lambda without IAM"
---
+
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
This is a follow-up for the serverless function from [Using Lambda without IAM user](/docs/lambda/using-lambda-without-iam-user).
### Prequisites
+
- Ensure that your local AWS profile is able to deploy to AWS.
### Setup
-#### 1. Clone or download the project
+#### 1. Clone or download the project
+
The project can be found at [`reference project`](https://github.com/alexfernandez803/example-lambda).
#### 2. Install dependencies
@@ -54,14 +55,15 @@ yarn install
</Tabs>
#### 3. Create the CDK Stack
+
This command will deploy the Lambda function and any other resources in the stack.
```bash
npx aws-cdk deploy \
--outputs-file ./cdk-outputs.json
```
-The Remotion packages are also bundled into the stack, these ensures that [`renderMediaOnLambda()`](/docs/lambda/rendermediaonlambda) can be executed by the [lambda function](https://github.com/alexfernandez803/example-lambda/blob/main/src/render-function/index.ts).
+The Remotion packages are also bundled into the stack, these ensures that [`renderMediaOnLambda()`](/docs/lambda/rendermediaonlambda) can be executed by the [lambda function](https://github.com/alexfernandez803/example-lambda/blob/main/src/render-function/index.ts).
```json title="package.json"
{
@@ -73,8 +75,8 @@ The Remotion packages are also bundled into the stack, these ensures that [`rend
}
```
-The full dependencies are included in the [reference project](https://github.com/alexfernandez803/example-lambda/blob/main/package.json).
+The full dependencies are included in the [reference project](https://github.com/alexfernandez803/example-lambda/blob/main/package.json).
#### 4. After deployment
@@ -82,6 +84,7 @@ The full dependencies are included in the [reference project](https://github.com
npx aws-cdk deploy \
--outputs-file ./cdk-outputs.json
```
+
Deployment progress
```bash
@@ -113,7 +116,7 @@ cdk-stack: deploying... [1/1]
✨ Deployment time: 1.39s
```
- Output
+Output
```bash
Outputs:
@@ -129,6 +132,7 @@ arn:aws:cloudformation:us-east-1:676583371711:stack/cdk-stack/faf43800-9878-11ed
The output contains the API Gateway base URL, region and Cognito client ID and user pool ID, which are used for authentication.
#### 5. Cleanup
+
The following will delete the function, in case it's not needed anymore.
```bash
@@ -136,10 +140,11 @@ npx aws-cdk destroy
```
## Lambda role
-The CDK creates an IAM role named `remotionLambdaServerlessRole` which needs the Remotion policy [setup](/docs/lambda/using-lambda-without-iam-user).
+The CDK creates an IAM role named `remotionLambdaServerlessRole` which needs the Remotion policy [setup](/docs/lambda/using-lambda-without-iam-user).
## Test your endpoint
+
The API is secured by Cognito which requires an authorization token.
In order to test, you need to do the steps below, just in case you still don't have frontend.
@@ -154,14 +159,15 @@ aws cognito-idp sign-up \
```
2. Confirm the user so they can sign in
-```bash
+
+```bash
aws cognito-idp admin-confirm-sign-up \
--user-pool-id YOUR_USER_POOL_ID \
--username "[email protected]"
```
-
3. Log the user to retrieve an identity JWT token
+
```bash
aws cognito-idp initiate-auth \
--auth-flow USER_PASSWORD_AUTH \
@@ -170,9 +176,11 @@ aws cognito-idp initiate-auth \
--client-id YOUR_USER_POOL_CLIENT_ID
```
+
YOUR_USER_POOL_CLIENT_ID and YOUR_USER_POOL_ID are part of CDK [output](/docs/lambda/example-setup-without-iam-user#output).
Output
+
```bash
{
"ChallengeParameters": {},
@@ -185,34 +193,38 @@ Output
}
}
```
+
The API will give you a verbose response but will only use the `IdToken`.
4. Use the token to invoke a request to the endpoint using curl.
- ##### Request
- ```bash
- curl --location --request POST 'https://du7jfr6.execute-api.us-east-1.amazonaws.com/render' \
- --header 'Authorization: Bearer eyJraWQiOiJGcUJFV1B1cHhxM0NXRko0RVN2..........'
- ```
- ##### Response
- ```bash
- {"message":"SUCCESS","bucketName":"remotionlambda-apsoutheast2-5essis84y1","renderId":"1pwhfhh11z"}
- ```
+##### Request
+```bash
+curl --location --request POST 'https://du7jfr6.execute-api.us-east-1.amazonaws.com/render' \
+--header 'Authorization: Bearer eyJraWQiOiJGcUJFV1B1cHhxM0NXRko0RVN2..........'
+```
-That's it! You now have an API that you can use to invoke the rendering of a video.
+##### Response
+```bash
+{"message":"SUCCESS","bucketName":"remotionlambda-apsoutheast2-5essis84y1","renderId":"1pwhfhh11z"}
+```
+
+That's it! You now have an API that you can use to invoke the rendering of a video.
:::warning
It is important to note that the Lambda function should not be accessible to unauthenticated users. The function uses version 2 of the CDK, which is still being actively developed.
:::warn
## Next Steps
+
- [Customize the Lambda function](https://github.com/alexfernandez803/example-lambda/blob/main/src/render-function/index.ts) so that the rendered video will be moved to another directory.
- Try assigning the Remotion [role](/docs/lambda/using-lambda-without-iam-user#1--create-role-policy) via CDK [`code`](https://github.com/alexfernandez803/example-lambda/blob/main/lib/remotion-cdk-starter-stack.ts).
- Add request parameters to the Lambda function as input parameters for [`renderMediaOnLambda()`](/docs/lambda/rendermediaonlambda).
-
+
## See also
+
- [Using Lambda without IAM user](/docs/lambda/using-lambda-without-iam-user)
- [Permissions](/docs/lambda/permissions)
- Some code is borrowed from [bobbyhadz.com](https://bobbyhadz.com/blog/aws-cdk-api-authorizer)
diff --git a/packages/docs/docs/lambda/usinglambdawithoutiamuser.md b/packages/docs/docs/lambda/without-iam/index.md
similarity index 82%
rename from packages/docs/docs/lambda/usinglambdawithoutiamuser.md
rename to packages/docs/docs/lambda/without-iam/index.md
index 1ce4f50896..11c5b95cd1 100644
--- a/packages/docs/docs/lambda/usinglambdawithoutiamuser.md
+++ b/packages/docs/docs/lambda/without-iam/index.md
@@ -1,29 +1,30 @@
---
-image: /generated/articles-docs-lambda-usinglambdawithoutiamuser.png
-id: usinglambdawithoutiamuser
+image: /generated/articles-docs-lambda-without-iam-index.png
title: Using Lambda without IAM user
-slug: /lambda/using-lambda-without-iam-user
-crumb: "Lambda"
+sidebar_label: "Overview"
+crumb: "Lambda without IAM"
---
-import {UserPolicy} from '../../components/lambda/user-permissions.tsx';
+import {UserPolicy} from '../../../components/lambda/user-permissions.tsx';
## Context
-As documented on [`permission`](/docs/lambda/permissions) we create a Remotion user and assign `policies`. These policies give permission to Lambda to render a video with [`renderMediaOnLambda()`](/docs/lambda/rendermediaonlambda). However, this approach poses security risks as the AWS access key ID and secret access key associated with the user are considered long-term credentials and could be inadvertently leaked. Additionally, there might be requirements to execute [`renderMediaOnLambda()`](/docs/lambda/rendermediaonlambda) on services such as [`Lambda`](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html), [`EC2`](https://aws.amazon.com/ec2/), and other [`computing services`](https://aws.amazon.com/products/compute/) where the use of long-term credentials is not an option.
+As documented on [`permission`](/docs/lambda/permissions) we create a Remotion user and assign `policies`. These policies give permission to Lambda to render a video with [`renderMediaOnLambda()`](/docs/lambda/rendermediaonlambda). However, this approach poses security risks as the AWS access key ID and secret access key associated with the user are considered long-term credentials and could be inadvertently leaked. Additionally, there might be requirements to execute [`renderMediaOnLambda()`](/docs/lambda/rendermediaonlambda) on services such as [`Lambda`](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html), [`EC2`](https://aws.amazon.com/ec2/), and other [`computing services`](https://aws.amazon.com/products/compute/) where the use of long-term credentials is not an option.
AWS offers the concept of [IAM Roles](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles) as a solution to the problem above. When a role is assigned to an AWS service, AWS gives any elevated privileges based on the attached policies and the role is empowered to execute activities such as putting a file to an S3 bucket. The role is given temporary AWS credentials such as `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, and `AWS_SESSION_TOKEN` to generate the video. This approach enhances security as there are no long-term credentials lingering around and the need to keep track of their rotation is eliminated.
The steps below provide authorization for the Lambda function to execute `renderMediaOnLambda()` without permission issues.
## Prerequisites
+
1. A deployed Lambda function running on AWS. An example that tells you how this is done is created [`here`](https://github.com/alexfernandez803/example-lambda) using [`CDK`](https://docs.aws.amazon.com/cdk/v2/guide/work-with-cdk-typescript.html). It gives you an idea how to call [`renderMediaOnLambda()`](/docs/lambda/rendermediaonlambda) inside another Lambda function. The function is triggered by [API Gateway](https://docs.aws.amazon.com/apigateway/latest/developerguide/welcome.html). The example assumes that you have knowledge of using [`CDK`](https://docs.aws.amazon.com/cdk/v2/guide/work-with-cdk-typescript.html), a [write up](/docs/lambda/example-setup-without-iam-user) for this is also created for anyone that wants to follow.
2. An execution role is assigned to the Lambda function
3. A user policy with the necessary [user permissions](/docs/lambda/permissions#user-permissions).
## Setup
-#### 1. Create role policy
+#### 1. Create role policy
+
- Go to the IAM policies section in the AWS Management Console
- Click on "Create policy"
- Click on JSON
@@ -36,63 +37,61 @@ The steps below provide authorization for the Lambda function to execute `render
- Click next. On the tags page, you don't need to fill in anything. Click next again.
- Give the policy the name `remotion-executionrole-policy`. The other fields can be left as they are.
-
#### 2. Assign the policy to the Lambda execution role
-- Go to the [AWS Management Console](https://console.aws.amazon.com/console/home) ➞ Navigate to [Lambda (change to your function region)](https://us-east-1.console.aws.amazon.com/lambda/home?region=us-east-1#/discover) ➞ [Functions](https://us-east-1.console.aws.amazon.com/lambda/home?region=us-east-1#/functions) ➞ Select your Lambda function ➞ Configuration tab ➞ Permissions tab ➞ Click the role under `Execution role` ➞ When redirected, click Permissions tab ➞ Click on `Add permissions` ➞ Attach policy ➞ Find the policy, i.e. `remotion-executionrole-policy` ➞ Select the policy ➞ Then click the `Attach policies` button.
-With the assignment of the `policy` to the Lambda execution role, it is now empowered to execute the [`renderMediaOnLambda()`](/docs/lambda/rendermediaonlambda) without permission issues. In the background, when the Lambda function is executed, it is provided with environment variables such as `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` and `AWS_SESSION_TOKEN` that has temporary permission to AWS resources that `renderMediaOnLambda()` requires to render the video. The elevated powers came from the policy statements in `remotion-executionrole-policy`.
+- Go to the [AWS Management Console](https://console.aws.amazon.com/console/home) ➞ Navigate to [Lambda (change to your function region)](https://us-east-1.console.aws.amazon.com/lambda/home?region=us-east-1#/discover) ➞ [Functions](https://us-east-1.console.aws.amazon.com/lambda/home?region=us-east-1#/functions) ➞ Select your Lambda function ➞ Configuration tab ➞ Permissions tab ➞ Click the role under `Execution role` ➞ When redirected, click Permissions tab ➞ Click on `Add permissions` ➞ Attach policy ➞ Find the policy, i.e. `remotion-executionrole-policy` ➞ Select the policy ➞ Then click the `Attach policies` button.
+With the assignment of the `policy` to the Lambda execution role, it is now empowered to execute the [`renderMediaOnLambda()`](/docs/lambda/rendermediaonlambda) without permission issues. In the background, when the Lambda function is executed, it is provided with environment variables such as `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` and `AWS_SESSION_TOKEN` that has temporary permission to AWS resources that `renderMediaOnLambda()` requires to render the video. The elevated powers came from the policy statements in `remotion-executionrole-policy`.
:::info
This procedure can be also applied to other AWS compute services such as `EC2`, `Fargate` etc..
:::
-## Optional
+## Optional
+
If you want to move the video to another S3 bucket after it is rendered, the Lambda function also needs permission to do so. The process is similar to the previous steps, but you will need to create a new policy statement that defines the bucket that Lambda needs to transfer the rendered video to.
- #### Example
- ```ts twoslash
- // @module: esnext
- // @target: es2017
- // ---cut---
-
- import { renderMediaOnLambda } from "@remotion/lambda/client";
-
- const { bucketName, renderId } = await renderMediaOnLambda({
- region: "us-east-1",
- functionName: "remotion-render-bds9aab",
- composition: "MyVideo",
- serveUrl:
- "https://remotionlambda-qg35eyp1s1.s3.eu-central-1.amazonaws.com/sites/bf2jrbfkw",
- codec: "h264",
- outName: "transfer-to-this-bucket-after-render/the-filename.mp4",
- });
- ```
+#### Example
+
+```ts twoslash
+// @module: esnext
+// @target: es2017
+// ---cut---
+
+import { renderMediaOnLambda } from "@remotion/lambda/client";
+
+const { bucketName, renderId } = await renderMediaOnLambda({
+ region: "us-east-1",
+ functionName: "remotion-render-bds9aab",
+ composition: "MyVideo",
+ serveUrl:
+ "https://remotionlambda-qg35eyp1s1.s3.eu-central-1.amazonaws.com/sites/bf2jrbfkw",
+ codec: "h264",
+ outName: "transfer-to-this-bucket-after-render/the-filename.mp4",
+});
+```
In the example above, the `renderMediaOnLambda()` is configured to output the rendered video to `transfer-to-this-bucket-after-render` bucket. The following steps allow Lambda to move the file to another bucket.
### Steps
+
- Again we assign the policy to the Lambda execution role. Go to the [AWS Management Console](https://console.aws.amazon.com/console/home) ➞ Navigate to [Lambda (change to your function region)](https://us-east-1.console.aws.amazon.com/lambda/home?region=us-east-1#/discover) ➞ [Functions](https://us-east-1.console.aws.amazon.com/lambda/home?region=us-east-1#/functions) ➞ Select your Lambda function ➞ Configuration tab ➞ Permissions tab ➞ Click the role under `Execution role` ➞ When redirected, click Permissions tab ➞ Click on `Add permissions` ➞ Click create inline policy.
- Click JSON tab
- Add a policy statement similar to the one below, which is defining the bucket Lambda needs to transfer the rendered video to.
```json
- {
- "Version": "2012-10-17",
- "Statement": [
- {
- "Action": [
- "s3:PutObject"
- ],
- "Resource": [
- "arn:aws:s3:::{bucketname}",
- "arn:aws:s3:::{bucketname}/*"
- ],
- "Effect": "Allow"
- }
- ]
+{
+ "Version": "2012-10-17",
+ "Statement": [
+ {
+ "Action": ["s3:PutObject"],
+ "Resource": ["arn:aws:s3:::{bucketname}", "arn:aws:s3:::{bucketname}/*"],
+ "Effect": "Allow"
+ }
+ ]
}
```
+
- Replace {bucketname} with the name of the bucket where you want to move the rendered video to.
- Click Click on `Review policy`
- Then click save changes
@@ -100,4 +99,5 @@ In the example above, the `renderMediaOnLambda()` is configured to output the re
The Lambda function can now move the rendered video to the other bucket when the render process is completed.
## See also
+
- [Example setup without IAM user](/docs/lambda/example-setup-without-iam-user)
diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.js
index 8b38ebbf78..51add35b01 100644
--- a/packages/docs/sidebars.js
+++ b/packages/docs/sidebars.js
@@ -406,8 +406,15 @@ module.exports = {
"lambda/troubleshooting/bucket-disallows-acl",
],
},
- "lambda/usinglambdawithoutiamuser",
- "lambda/examplesetupwithoutiamuser",
+ {
+ type: "category",
+ label: "Using without IAM",
+ link: {
+ type: "doc",
+ id: "lambda/without-iam/index",
+ },
+ items: ["lambda/without-iam/index", "lambda/without-iam/example"],
+ },
"lambda/optimizing-cost",
"lambda/optimizing-speed",
"lambda/limits",
diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.ts
index 1480b19c2b..3f9d833a18 100644
--- a/packages/docs/src/data/articles.ts
+++ b/packages/docs/src/data/articles.ts
@@ -615,13 +615,6 @@ export const articles = [
compId: "articles-docs-lambda-estimateprice",
crumb: "Lambda API",
},
- {
- id: "examplesetupwithoutiamuser",
- title: "Example setup without IAM user",
- relativePath: "docs/lambda/examplesetupwithoutiamuser.md",
- compId: "articles-docs-lambda-examplesetupwithoutiamuser",
- crumb: "Lambda",
- },
{
id: "lambda/faq",
title: "FAQ",
@@ -839,13 +832,6 @@ export const articles = [
compId: "articles-docs-lambda-upgrading",
crumb: null,
},
- {
- id: "usinglambdawithoutiamuser",
- title: "Using Lambda without IAM user",
- relativePath: "docs/lambda/usinglambdawithoutiamuser.md",
- compId: "articles-docs-lambda-usinglambdawithoutiamuser",
- crumb: "Lambda",
- },
{
id: "validatewebhooksignature",
title: "validateWebhookSignature()",
@@ -860,6 +846,20 @@ export const articles = [
compId: "articles-docs-lambda-webhooks",
crumb: "Lambda",
},
+ {
+ id: "lambda/without-iam/example",
+ title: "Example setup without IAM user",
+ relativePath: "docs/lambda/without-iam/example.md",
+ compId: "articles-docs-lambda-without-iam-example",
+ crumb: "Lambda without IAM",
+ },
+ {
+ id: "lambda/without-iam/index",
+ title: "Using Lambda without IAM user",
+ relativePath: "docs/lambda/without-iam/index.md",
+ compId: "articles-docs-lambda-without-iam-index",
+ crumb: "Lambda without IAM",
+ },
{
id: "lambda",
title: "@remotion/lambda",
diff --git a/packages/docs/static/generated/articles-docs-lambda-examplesetupwithoutiamuser.png b/packages/docs/static/generated/articles-docs-lambda-examplesetupwithoutiamuser.png
deleted file mode 100644
index d9ca3a47de..0000000000
Binary files a/packages/docs/static/generated/articles-docs-lambda-examplesetupwithoutiamuser.png and /dev/null differ
diff --git a/packages/docs/static/generated/articles-docs-lambda-usinglambdawithoutiamuser.png b/packages/docs/static/generated/articles-docs-lambda-usinglambdawithoutiamuser.png
deleted file mode 100644
index 27a8bef647..0000000000
Binary files a/packages/docs/static/generated/articles-docs-lambda-usinglambdawithoutiamuser.png and /dev/null differ
diff --git a/packages/docs/static/generated/articles-docs-lambda-without-iam-example.png b/packages/docs/static/generated/articles-docs-lambda-without-iam-example.png
new file mode 100644
index 0000000000..d44deeaa0a
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-lambda-without-iam-example.png differ
diff --git a/packages/docs/static/generated/articles-docs-lambda-without-iam-index.png b/packages/docs/static/generated/articles-docs-lambda-without-iam-index.png
new file mode 100644
index 0000000000..c85ab14230
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-lambda-without-iam-index.png differ