Skip to content

πŸŽ₯ Make videos programmatically with React

copywriting

Jonny Burger5bc053c7ad8d
diff --git a/packages/docs/docs/lambda/without-iam/example.md b/packages/docs/docs/lambda/without-iam/example.md
index 8880f8d136..eda1948a62 100644
--- a/packages/docs/docs/lambda/without-iam/example.md
+++ b/packages/docs/docs/lambda/without-iam/example.md
@@ -7,19 +7,19 @@ 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).
+This is a write up of how to use the [example](https://github.com/alexfernandez803/example-lambda) for the technique described under ["Using Lambda without an IAM user"](/docs/lambda/without-iam).
-### Prequisites
+## Prequisites
- Ensure that your local AWS profile is able to deploy to AWS.
-### Setup
+## 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
+### 2. Install dependencies
<Tabs
defaultValue="npm"
@@ -54,7 +54,7 @@ yarn install
</Tabs>
-#### 3. Create the CDK Stack
+### 3. Create the CDK Stack
This command will deploy the Lambda function and any other resources in the stack.
@@ -63,13 +63,13 @@ 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"
{
"dependencies": {
...
- "remotion": "^3.3.33",
+ "remotion": "^3.3.33",
"@remotion/lambda": "^3.3.33",
}
}
@@ -78,16 +78,14 @@ 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).
-#### 4. After deployment
+### 4. After deployment
```bash
npx aws-cdk deploy \
--outputs-file ./cdk-outputs.json
```
-Deployment progress
-
-```bash
+```bash title="Deployment progress"
Bundling asset cdk-stack/render-function/Code/Stage...
cdk.out/bundling-temp-5e88d0b45626d59e8e8ddce3b05a886b0e1b381df6e5bbbea1dc2727080641a8/index.js 6.3mb ⚠️
@@ -116,9 +114,7 @@ cdk-stack: deploying... [1/1]
✨ Deployment time: 1.39s
```
-Output
-
-```bash
+```bash title="Output"
Outputs:
cdk-stack.apiUrl = https://du7jfr.execute-api.us-east-1.amazonaws.com/
cdk-stack.region = us-east-1
@@ -131,7 +127,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
+### 5. Cleanup
The following will delete the function, in case it's not needed anymore.
@@ -141,7 +137,7 @@ 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/without-iam).
## Test your endpoint
@@ -149,7 +145,7 @@ 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.
-1. Create a Cognito User
+### 1. Create a Cognito User
```bash
aws cognito-idp sign-up \
@@ -158,7 +154,7 @@ aws cognito-idp sign-up \
--password "compLicat3d123"
```
-2. Confirm the user so they can sign in
+### 2. Confirm the user so they can sign in
```bash
aws cognito-idp admin-confirm-sign-up \
@@ -166,7 +162,7 @@ aws cognito-idp admin-confirm-sign-up \
--username "[email protected]"
```
-3. Log the user to retrieve an identity JWT token
+### 3. Log the user to retrieve an identity JWT token
```bash
aws cognito-idp initiate-auth \
@@ -177,11 +173,9 @@ aws cognito-idp initiate-auth \
```
-YOUR_USER_POOL_CLIENT_ID and YOUR_USER_POOL_ID are part of CDK [output](/docs/lambda/example-setup-without-iam-user#output).
-
-Output
+`YOUR_USER_POOL_CLIENT_ID` and `YOUR_USER_POOL_ID` are part of the CDK output.
-```bash
+```bash title="Output"
{
"ChallengeParameters": {},
"AuthenticationResult": {
@@ -196,16 +190,16 @@ 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.
+### 4. Use the token to invoke a request to the endpoint using curl.
-##### Request
+#### Request
```bash
curl --location --request POST 'https://du7jfr6.execute-api.us-east-1.amazonaws.com/render' \
--header 'Authorization: Bearer eyJraWQiOiJGcUJFV1B1cHhxM0NXRko0RVN2..........'
```
-##### Response
+#### Response
```bash
{"message":"SUCCESS","bucketName":"remotionlambda-apsoutheast2-5essis84y1","renderId":"1pwhfhh11z"}
@@ -214,17 +208,18 @@ curl --location --request POST 'https://du7jfr6.execute-api.us-east-1.amazonaws.
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
+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.
+:::
## 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).
+- Try assigning the Remotion [role](/docs/lambda/without-iam#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)
+- [Using Lambda without IAM user](/docs/lambda/without-iam)
- [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/without-iam/index.md b/packages/docs/docs/lambda/without-iam/index.md
index 11c5b95cd1..e82d42ae52 100644
--- a/packages/docs/docs/lambda/without-iam/index.md
+++ b/packages/docs/docs/lambda/without-iam/index.md
@@ -1,29 +1,33 @@
---
image: /generated/articles-docs-lambda-without-iam-index.png
-title: Using Lambda without IAM user
+title: Using Lambda without an IAM user
sidebar_label: "Overview"
crumb: "Lambda without IAM"
---
import {UserPolicy} from '../../../components/lambda/user-permissions.tsx';
-## Context
+As documented on the [`Permissions page`](/docs/lambda/permissions), the default way of using Remotion Lambda involves creating a Remotion user and assign it policies.
-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.
+These policies give permission to Lambda to render a video with [`renderMediaOnLambda()`](/docs/lambda/rendermediaonlambda). These credentials are considered long-term which is less secure and are disallowed in some companies.
-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.
+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
+1. A deployed Lambda function running on AWS. An example using [`CDK`](https://docs.aws.amazon.com/cdk/v2/guide/work-with-cdk-typescript.html) is available [`here`](https://github.com/alexfernandez803/example-lambda). 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/without-iam/example) is also available.
+2. An execution role that 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"
@@ -37,23 +41,39 @@ 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
+### 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)
+ - Select [Functions](https://us-east-1.console.aws.amazon.com/lambda/home?region=us-east-1#/functions)
+ - Select your Lambda function
+ - Select the "Configuration" tab
+ - Select the "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
+ - Click the `Attach policies` button.
-- 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) API without permission issues.
-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`.
+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 come from the policy statements in `remotion-executionrole-policy`.
-:::info
+:::note
This procedure can be also applied to other AWS compute services such as `EC2`, `Fargate` etc..
:::
-## Optional
+## Render into a different bucket
-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.
+Optionally, 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
+### Example
-```ts twoslash
+Use the `outName` property to select a different bucket. See: [Custom output destination](/docs/lambda/custom-destination)
+
+```ts twoslash title="my-function.ts"
// @module: esnext
// @target: es2017
// ---cut---
@@ -67,7 +87,10 @@ const { bucketName, renderId } = await renderMediaOnLambda({
serveUrl:
"https://remotionlambda-qg35eyp1s1.s3.eu-central-1.amazonaws.com/sites/bf2jrbfkw",
codec: "h264",
- outName: "transfer-to-this-bucket-after-render/the-filename.mp4",
+ outName: {
+ key: "my-output",
+ bucketName: "output-bucket",
+ },
});
```
@@ -75,9 +98,19 @@ In the example above, the `renderMediaOnLambda()` is configured to output the re
### 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.
+- Again we assign the policy to the Lambda execution role. Go to the [AWS Management Console](https://console.aws.amazon.com/console/home) and:
+ - 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 the "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
{
@@ -92,12 +125,12 @@ In the example above, the `renderMediaOnLambda()` is configured to output the re
}
```
-- 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
+- Replace `{bucketname}` with the name of the bucket where you want to move the rendered video to.
+- Click on `Review policy`
+- Click `Save changes`
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)
+- [Example setup without IAM user](/docs/lambda/without-iam/example)