Skip to content

πŸŽ₯ Make videos programmatically with React

initial article details

Alex Fernandezbd0c5eb00c6e
diff --git a/packages/docs/docs/lambda/aws-sqs-lambda-integration.md b/packages/docs/docs/lambda/aws-sqs-lambda-integration.md
new file mode 100644
index 0000000000..ac46c3ce82
--- /dev/null
+++ b/packages/docs/docs/lambda/aws-sqs-lambda-integration.md
@@ -0,0 +1,372 @@
+---
+title: Using the AWS SQS with Remotion Lambda
+slug: /lambda/aws-sqs-lambda-integration
+sidebar_label: AWS SQS and Remotion Lambda
+crumb: "@remotion/lambda"
+---
+
+import Tabs from '@theme/Tabs';
+import TabItem from '@theme/TabItem';
+
+This guide will show you how to use [Amazon SQS](https://aws.amazon.com/sqs/) and Remotion's [rendermediaonlambda](/docs/lambda/rendermediaonlambda). Queues are used to park request to make way for the underlying resources to cope up demand. For Remotion there can be instances that demands exceeds the Lambda concurrency limit on rendering the videos, the use of SQS is a workaround to handle the load as the render process is executed in the background and you just notify the user when the render process is completed by the sending them email or means of notification.
+
+To supplement this guide, two projects have been created. The [remotion-app](https://github.com/alexfernandez803/remotion-serverless/tree/main/remotion-app) contains a Remotion composition and utility scripts for deploying and deleting Remotion Lambda infrastructure in AWS. Note that this is the same application from [Serverless Framework guide](/docs/lambda/serverless-framework-integration).
+
+The [apigw-sqs-app](https://github.com/alexfernandez803/remotion-serverless/tree/main/apigw-sqs-app) contains a [CDK](https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html) project that deploys two Lambda functions. The [enqueue-function](https://github.com/alexfernandez803/remotion-serverless/blob/main/apigw-sqs-app/src/enqueue-function/index.ts) function, when invoked, queues a `JSON` data sent by the user; this can be an `input` properties for the Remotion Lambda. The [render-lambda-function](https://github.com/alexfernandez803/remotion-serverless/blob/main/apigw-sqs-app/src/render-lambda-function/index.ts) function listens to enqueued message from `SQS`, processe it and for this instance render the video.
+
+The `enqueue-function` is configured to be invoked through [API Gateway](https://aws.amazon.com/api-gateway/) and are secured by [Cognito](https://aws.amazon.com/cognito/). The API Gateway and Cognito setup is automatically created by the [CDK Stack](https://github.com/alexfernandez803/remotion-serverless/blob/main/apigw-sqs-app/lib/remotion-cdk-starter-stack.ts) deployment upon execution of `cdk deploy`.
+
+This assumes that you have knowledge in using [CDK with TypeScript](https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html) and [AWS SQS knowledge](https://aws.amazon.com/sqs/). The AWS Cloud Development Kit (CDK) has been chosen to provision infrastructure as it is an official library from [AWS](https://aws.amazon.com). Using manual creation in the AWS console can lead to errors, making the CDK a more reliable option.
+
+## remotion-app
+- Follow exactly the same setup instruction from [remotion-app guide](/lambda/serverless-framework-integration#remotion-app).
+
+## apigw-sqs-app
+
+This contains instructions for setting up and installing Lambda services [enqueue-function](https://github.com/alexfernandez803/remotion-serverless/blob/main/apigw-sqs-app/src/enqueue-function/index.ts) and [render-lambda-function](https://github.com/alexfernandez803/remotion-serverless/blob/main/apigw-sqs-app/src/render-lambda-function/index.ts) to your AWS account. This guide is designed to be executed on your local machine.
+
+### Context
+- TODO
+
+### Prerequisites
+
+- 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).
+
+### Setup
+
+#### 1. Clone or download the project
+
+The project can be found at [`remotion-serverless project`](https://github.com/alexfernandez803/remotion-serverless).
+If not done in the previous step, clone the project using:
+
+```bash
+git clone https://github.com/alexfernandez803/remotion-serverless
+```
+
+#### 2. Go to `remotion-serverless` and traverse to `apigw-sqs-app` directory
+
+```bash
+cd remotion-serverless && cd apigw-sqs-app
+```
+
+#### 3. Install dependencies
+
+<Tabs
+defaultValue="npm"
+values={[
+{ label: 'npm', value: 'npm', },
+{ label: 'yarn', value: 'yarn', },
+{ label: 'pnpm', value: 'pnpm', },
+]
+}>
+<TabItem value="npm">
+
+```bash
+npm i
+```
+
+ </TabItem>
+
+ <TabItem value="pnpm">
+
+```bash
+pnpm i
+```
+
+ </TabItem>
+ <TabItem value="yarn">
+
+```bash
+yarn
+```
+
+ </TabItem>
+
+</Tabs>
+
+#### 4. Create the Remotion policy
+- The `remotion-executionrole-policy` should have been created, if not, follow this [guide](/docs/lambda/without-iam/#1-create-role-policy) in setting this up.
+
+The `remotion-executionrole-policy` is referenced from [here](https://github.com/alexfernandez803/remotion-serverless/blob/main/apigw-sqs-app/lib/remotion-cdk-starter-stack.ts#L64). The `CDK` stack creates a role for `render-lambda-function` with the `remotion-executionrole-policy`.
+
+```ts
+// πŸ‘‡ create a role with custom name
+ const renderFunctionLambdaRole = new Role(this, "remotionSQSLambdaRole", {
+ roleName: "remotionSQSLambdaRole",
+ assumedBy: new ServicePrincipal("lambda.amazonaws.com"),
+ managedPolicies: [
+ ManagedPolicy.fromAwsManagedPolicyName(
+ "service-role/AWSLambdaBasicExecutionRole"
+ ),
+ ManagedPolicy.fromManagedPolicyName(
+ this,
+ "remotion-executionrole-policy",
+ "remotion-executionrole-policy"
+ ),
+ ],
+ });
+```
+This creates a role in AWS with the name of `remotionSQSLambdaRole` with 2 policies attached:
+- `service-role/AWSLambdaBasicExecutionRole` grants permission to the Lambda function to interact with and log information to [Cloudwatch](https://aws.amazon.com/cloudwatch/). This policy is part of the AWS library of policies.
+- `remotion-executionrole-policy` policy grants permission to the Lambda function to interact to AWS services that Remotion Lambda needs access to, in this render a video. This policy is exactly the same policy from this [guide](/docs/lambda/without-iam/#1-create-role-policy).
+
+
+#### 5. Optional - Synthesize
+
+From the `apigw-sqs-app` directory, execute the `cdk synthesize` command.
+
+```bash
+ cdk synthesize
+```
+This command will show the [Cloud Formation Template](https://aws.amazon.com/cloudformation/) that CDK will deploy to your AWS account.
+
+
+#### 6. Deploy the apigw-sqs-app project
+
+From the `apigw-sqs-app` directory, execute the `cdk deploy` command.
+
+```bash
+ cdk deploy
+```
+
+This will deploy the functions,
+
+```bash title="deploy"
+ Bundling asset apigw-sqs-app-stack/enqueue-function/Code/Stage...
+
+ cdk.out/bundling-temp-a813aece2454684086de775f918faac45b1b77c67fff24ec6aad4bff8c978ebe/index.js 881.5kb
+
+⚑ Done in 72ms
+Bundling asset apigw-sqs-app-stack/render-function/Code/Stage...
+
+ cdk.out/bundling-temp-e7d973ee34691a8e6a2ceda969fbf59380866bb486be333238b7e554907f7b95/index.js 2.6kb
+
+⚑ Done in 2ms
+
+added 279 packages, and audited 280 packages in 2s
+
+21 packages are looking for funding
+ run `npm fund` for details
+
+found 0 vulnerabilities
+
+✨ Synthesis time: 7.97s
+
+apigw-sqs-app-stack: building assets...
+
+[0%] start: Building 8efaff13bbe794558db1f1cb8f506bc13b87d7ab3e568ebc324bac680da3a75d:XXXXXXXXXX-ap-southeast-2
+[0%] start: Building 3b7a9f596977e2db94a676c6c89c99dd7eb87a5985f97a11ff23b9f338027764:XXXXXXXXXX-ap-southeast-2
+[0%] start: Building cf7f13fe5c0ff3b22e7352152a554dd8a4767f6a5e2285e6bf353fc42070e697:XXXXXXXXXX-ap-southeast-2
+[33%] success: Built 8efaff13bbe794558db1f1cb8f506bc13b87d7ab3e568ebc324bac680da3a75d:XXXXXXXXXX-ap-southeast-2
+[66%] success: Built 3b7a9f596977e2db94a676c6c89c99dd7eb87a5985f97a11ff23b9f338027764:XXXXXXXXXX-ap-southeast-2
+[100%] success: Built cf7f13fe5c0ff3b22e7352152a554dd8a4767f6a5e2285e6bf353fc42070e697:XXXXXXXXXX-ap-southeast-2
+
+apigw-sqs-app-stack: assets built
+
+This deployment will make potentially sensitive changes according to your current security approval level (--require-approval broadening).
+Please confirm you intend to make the following modifications:
+
+IAM Statement Changes
+β”Œβ”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
+β”‚ β”‚ Resource β”‚ Effect β”‚ Action β”‚ Principal β”‚ Condition β”‚
+β”œβ”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
+β”‚ + β”‚ ${api-integration-role.Arn} β”‚ Allow β”‚ sts:AssumeRole β”‚ Service:lambda.amazonaws.co β”‚ β”‚
+β”‚ β”‚ β”‚ β”‚ β”‚ m β”‚ β”‚
+β”œβ”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
+β”‚ + β”‚ ${enqueue-function.Arn} β”‚ Allow β”‚ lambda:InvokeFunction β”‚ Service:apigateway.amazonaw β”‚ "ArnLike": { β”‚
+β”‚ β”‚ β”‚ β”‚ β”‚ s.com β”‚ "AWS:SourceArn": "arn:${AWS: β”‚
+β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ :Partition}:execute-api:ap-sou β”‚
+β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ theast-2:XXXXXXXXXX:${apiC85 β”‚
+β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ 50315}/*/*/enqueue" β”‚
+β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ } β”‚
+β”‚ + β”‚ ${enqueue-function.Arn} β”‚ Allow β”‚ lambda:InvokeFunction β”‚ Service:apigateway.amazonaw β”‚ "ArnLike": { β”‚
+β”‚ β”‚ β”‚ β”‚ β”‚ s.com β”‚ "AWS:SourceArn": "arn:${AWS: β”‚
+β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ :Partition}:execute-api:ap-sou β”‚
+β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ theast-2:XXXXXXXXXX:${apiC85 β”‚
+β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ 50315}/*/*/enqueue" β”‚
+β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ } β”‚
+β”œβ”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
+β”‚ + β”‚ ${queue.Arn} β”‚ Allow β”‚ sqs:ChangeMessageVisibility β”‚ AWS:${remotionSQSLambdaRole β”‚ β”‚
+β”‚ β”‚ β”‚ β”‚ sqs:DeleteMessage β”‚ } β”‚ β”‚
+β”‚ β”‚ β”‚ β”‚ sqs:GetQueueAttributes β”‚ β”‚ β”‚
+β”‚ β”‚ β”‚ β”‚ sqs:GetQueueUrl β”‚ β”‚ β”‚
+β”‚ β”‚ β”‚ β”‚ sqs:ReceiveMessage β”‚ β”‚ β”‚
+β”‚ + β”‚ ${queue.Arn} β”‚ Allow β”‚ sqs:GetQueueAttributes β”‚ AWS:${api-integration-role} β”‚ β”‚
+β”‚ β”‚ β”‚ β”‚ sqs:GetQueueUrl β”‚ β”‚ β”‚
+β”‚ β”‚ β”‚ β”‚ sqs:SendMessage β”‚ β”‚ β”‚
+β”œβ”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
+β”‚ + β”‚ ${remotionSQSLambdaRole.Arn β”‚ Allow β”‚ sts:AssumeRole β”‚ Service:lambda.amazonaws.co β”‚ β”‚
+β”‚ β”‚ } β”‚ β”‚ β”‚ m β”‚ β”‚
+β””β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
+IAM Policy Changes
+β”Œβ”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
+β”‚ β”‚ Resource β”‚ Managed Policy ARN β”‚
+β”œβ”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
+β”‚ + β”‚ ${api-integration-role} β”‚ arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole β”‚
+β”œβ”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
+β”‚ + β”‚ ${remotionSQSLambdaRole} β”‚ arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole β”‚
+β”‚ + β”‚ ${remotionSQSLambdaRole} β”‚ arn:${AWS::Partition}:iam::XXXXXXXXXX:policy/remotion-executionrole-policy β”‚
+β””β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
+(NOTE: There may be security-related changes not in this list. See https://github.com/aws/aws-cdk/issues/1299)
+
+Do you wish to deploy these changes (y/n)? y
+
+```
+
+Select 'y' for the answer of the prompt and CDK will continue to deploy the Stack, with the 2 function.
+
+```bash title="final output"
+apigw-sqs-app-stack: deploying... [1/1]
+[0%] start: Publishing 8efaff13bbe794558db1f1cb8f506bc13b87d7ab3e568ebc324bac680da3a75d:XXXXXXXXXX-ap-southeast-2
+[0%] start: Publishing 3b7a9f596977e2db94a676c6c89c99dd7eb87a5985f97a11ff23b9f338027764:XXXXXXXXXX-ap-southeast-2
+[0%] start: Publishing cf7f13fe5c0ff3b22e7352152a554dd8a4767f6a5e2285e6bf353fc42070e697:XXXXXXXXXX-ap-southeast-2
+[33%] success: Published 3b7a9f596977e2db94a676c6c89c99dd7eb87a5985f97a11ff23b9f338027764:XXXXXXXXXX-ap-southeast-2
+[66%] success: Published 8efaff13bbe794558db1f1cb8f506bc13b87d7ab3e568ebc324bac680da3a75d:XXXXXXXXXX-ap-southeast-2
+[100%] success: Published cf7f13fe5c0ff3b22e7352152a554dd8a4767f6a5e2285e6bf353fc42070e697:XXXXXXXXXX-ap-southeast-2
+apigw-sqs-app-stack: creating CloudFormation changeset...
+
+ βœ… apigw-sqs-app-stack
+
+✨ Deployment time: 158.36s
+
+Outputs:
+apigw-sqs-app-stack.apiUrl = https://6mvgq2iad9.execute-api.ap-southeast-2.amazonaws.com/
+apigw-sqs-app-stack.queuearn = arn:aws:sqs:ap-southeast-2:XXXXXXXXXX:remotion_queue
+apigw-sqs-app-stack.queuename = remotion_queue
+apigw-sqs-app-stack.queueurl = https://sqs.ap-southeast-2.amazonaws.com/XXXXXXXXXX/remotion_queue
+apigw-sqs-app-stack.region = ap-southeast-2
+apigw-sqs-app-stack.userPoolClientId = 5d88adjpffj314pm4pot8g292i
+apigw-sqs-app-stack.userPoolId = ap-southeast-2_vzSlhO9O0
+Stack ARN:
+arn:aws:cloudformation:ap-southeast-2:XXXXXXXXXX:stack/apigw-sqs-app-stack/acb8b8f0-a52a-11ed-a440-024da00b5a8e
+
+```
+The deployment will provide an output such as `apigw-sqs-app-stack.region`, `apigw-sqs-app-stack.userPoolClientId`, and `apigw-sqs-app-stack.userPoolId `.
+
+
+#### 8. Remove the apigw-sqs-app from your AWS account, if not needed anymore
+
+From the `apigw-sqs-app` directory.
+
+```bash
+ cdk destroy
+```
+### CDK Stack
+
+### API Gateway, Remotion Lambda, and Queue
+
+ From [CDK stack code](https://github.com/alexfernandez803/remotion-serverless/blob/main/apigw-sqs-app/lib/remotion-cdk-starter-stack.ts#L64).
+
+ - The stack creates a queue named `remotion_queue`.
+ ```bash title="create queue"
+ // πŸ‘‡ create the queue
+ const remotionQueue = new sqs.Queue(this, "queue", {
+ encryption: sqs.QueueEncryption.KMS_MANAGED,
+ queueName: "remotion_queue",
+ });
+
+ ```
+ - `remotion_queue` grants access to 2 Lambda functions to interact with it.
+ ```bash title="apiIntegrationRole"
+ // πŸ‘‡ create the apiIntegrationRole role
+ const apiIntegrationRole = new IAM.Role(this, "api-integration-role", {
+ assumedBy: new IAM.ServicePrincipal("lambda.amazonaws.com"),
+ managedPolicies: [
+ ManagedPolicy.fromAwsManagedPolicyName(
+ "service-role/AWSLambdaBasicExecutionRole"
+ ),
+ ],
+ });
+ ```
+ This role is assigned to [enqueue-function](https://github.com/alexfernandez803/remotion-serverless/blob/main/apigw-sqs-app/lib/remotion-cdk-starter-stack.ts#L86), with access to Cloudwatch.
+
+
+ ```bash title="remotionSQSLambdaRole"
+ // πŸ‘‡ create a role with custom name
+ const renderFunctionLambdaRole = new Role(this, "remotionSQSLambdaRole", {
+ roleName: "remotionSQSLambdaRole",
+ assumedBy: new ServicePrincipal("lambda.amazonaws.com"),
+ managedPolicies: [
+ ManagedPolicy.fromAwsManagedPolicyName(
+ "service-role/AWSLambdaBasicExecutionRole"
+ ),
+ ManagedPolicy.fromManagedPolicyName(
+ this,
+ "remotion-executionrole-policy",
+ "remotion-executionrole-policy"
+ ),
+ ],
+ });
+ ```
+ This role is assigned to [render-lambda-function](https://github.com/alexfernandez803/remotion-serverless/blob/main/apigw-sqs-app/lib/remotion-cdk-starter-stack.ts#L97), with access to interact to Cloudwatch and permissions to access other AWS services specified by `remotion-executionrole-policy`.
+
+ ```bash title="grant access to the queue"
+ // πŸ‘‡ grant permission enqueue function to publish to the queue
+ remotionQueue.grantSendMessages(apiIntegrationRole);
+ // πŸ‘‡ grant permission to render function consume the queue
+ remotionQueue.grantConsumeMessages(renderFunctionLambdaRole);
+ ```
+ - Allow render function to listen to the queue
+
+ ```bash title="listen to queue"
+ remotionRenderFunction.addEventSource(
+ new SqsEventSource(remotionQueue, {
+ batchSize: 1,
+ maxBatchingWindow: Duration.minutes(5),
+ reportBatchItemFailures: true, // default to false
+ })
+ );
+ ```
+
+
+### Interacting with the API
+
+The API requires an authorization token to interact with it. To obtain the token, first go to the serverless dashboard to retrieve outputs such as `apigw-sqs-app-stack.region`, `apigw-sqs-app-stack.userPoolClientId`, and `apigw-sqs-app-stack.userPoolId`, which are used to authenticate with Cognito. If you do not have a frontend application, you can create a user and an authentication token manually for the API by following this [guide](docs/lambda/without-iam/example#test-your-endpoint).
+
+From the guide, `YOUR_USER_POOL_CLIENT_ID` is `apigw-sqs-app-stack.userPoolClientId` and `YOUR_USER_POOL_ID` is the `apigw-sqs-app-stack.userPoolId`, the steps should be followed up to retrieving the `IdToken`.
+
+The base API URL is `https://25w651t09g.execute-api.ap-southeast-2.amazonaws.com/dev/render` from the dashboard output `APIGatewayUrl`.
+
+#### 1. Render a video
+
+```bash title="render video"
+curl --location --request POST 'https://xxxxxxxx.execute-api.ap-southeast-2.amazonaws.com/dev/render' \
+--header 'Authorization: Bearer eyJraWQiOiJMVVVVZGtIQ1JXWEEyWEEXXXXXXXXXjMKR1t5S-oA'
+```
+
+```bash title="response"
+{
+ "message": "Video sent for rendering.",
+ "renderId": "i9xnfrgXXXX",
+ "bucketName": "remotionlambda-apsoutheast2-xxxxxxxx"
+}
+```
+
+This will initiate the render of the video and provide output with the `renderId` and `bucketName`. The code for the Lambda function is located [here](https://github.com/alexfernandez803/remotion-serverless/blob/main/serverless-app/render_handler.ts).
+
+#### 2. Get the progress of the render
+
+```bash title="progress"
+curl --location --request GET 'https://xxxxxxxx.execute-api.ap-southeast-2.amazonaws.com/dev/render/i9xnfrgXXXX?bucketName=remotionlambda-apsoutheast2-xxxxxxxx' \
+--header 'Authorization: Bearer eyJraWQiOiJMVVVVZGtIQ1JXWEEXXXXXXXXXXXvaQ'
+```
+
+```bash title="response"
+{
+ "message":"Message Send to SQS- Here is MessageId: a6abd0bc-b838-48b5-a562-4c511fac5b2f"
+}
+```
+
+This API will provide the progress details of the render, indicating whether it is a `success` or `failure`. If the video render is completed, it will provide the `mediaUrl`, which is a pre-signed URL that makes the video downloadable. The code for the Lambda function is located [here](https://github.com/alexfernandez803/remotion-serverless/blob/main/serverless-app/progress_handler.ts).
+
+## Notes
+
+- The deployment of Remotion Lambda is configured to be deployed only to `ap-southeast-2` region to simplify the project, adjust this in the code at [region.ts](https://github.com/alexfernandez803/remotion-serverless/blob/main/remotion-app/src/infra/regions.ts).
+
+## See also
+
+- [Using Lambda without IAM user](/docs/lambda/without-iam)
+- [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/without-iam/example.md b/packages/docs/docs/lambda/without-iam/example.md
index 9e167f84ed..8c345790ca 100644
--- a/packages/docs/docs/lambda/without-iam/example.md
+++ b/packages/docs/docs/lambda/without-iam/example.md
@@ -97,18 +97,18 @@ Bundling asset cdk-stack/render-function/Code/Stage...
cdk-stack: building assets...
-[0%] start: Building 87d5e793cbd198c73c05023515153b142eb2f559e7150579cd2db53362c19b6e:676583371711-us-east-1
-[0%] start: Building 779e5babb0ddf0d17c0faebbe5596b03bcf13785f0b20c4cd0fe0c5e616d5593:676583371711-us-east-1
-[50%] success: Built 87d5e793cbd198c73c05023515153b142eb2f559e7150579cd2db53362c19b6e:676583371711-us-east-1
-[100%] success: Built 779e5babb0ddf0d17c0faebbe5596b03bcf13785f0b20c4cd0fe0c5e616d5593:676583371711-us-east-1
+[0%] start: Building 87d5e793cbd198c73c05023515153b142eb2f559e7150579cd2db53362c19b6e:XXXXXXXXXX-us-east-1
+[0%] start: Building 779e5babb0ddf0d17c0faebbe5596b03bcf13785f0b20c4cd0fe0c5e616d5593:XXXXXXXXXX-us-east-1
+[50%] success: Built 87d5e793cbd198c73c05023515153b142eb2f559e7150579cd2db53362c19b6e:XXXXXXXXXX-us-east-1
+[100%] success: Built 779e5babb0ddf0d17c0faebbe5596b03bcf13785f0b20c4cd0fe0c5e616d5593:XXXXXXXXXX-us-east-1
cdk-stack: assets built
cdk-stack: deploying... [1/1]
-[0%] start: Publishing 87d5e793cbd198c73c05023515153b142eb2f559e7150579cd2db53362c19b6e:676583371711-us-east-1
-[0%] start: Publishing 779e5babb0ddf0d17c0faebbe5596b03bcf13785f0b20c4cd0fe0c5e616d5593:676583371711-us-east-1
-[50%] success: Published 779e5babb0ddf0d17c0faebbe5596b03bcf13785f0b20c4cd0fe0c5e616d5593:676583371711-us-east-1
-[100%] success: Published 87d5e793cbd198c73c05023515153b142eb2f559e7150579cd2db53362c19b6e:676583371711-us-east-1
+[0%] start: Publishing 87d5e793cbd198c73c05023515153b142eb2f559e7150579cd2db53362c19b6e:XXXXXXXXXX-us-east-1
+[0%] start: Publishing 779e5babb0ddf0d17c0faebbe5596b03bcf13785f0b20c4cd0fe0c5e616d5593:XXXXXXXXXX-us-east-1
+[50%] success: Published 779e5babb0ddf0d17c0faebbe5596b03bcf13785f0b20c4cd0fe0c5e616d5593:XXXXXXXXXX-us-east-1
+[100%] success: Published 87d5e793cbd198c73c05023515153b142eb2f559e7150579cd2db53362c19b6e:XXXXXXXXXX-us-east-1
βœ… cdk-stack (no changes)
@@ -122,7 +122,7 @@ cdk-stack.region = us-east-1
cdk-stack.userPoolClientId = 4l5tsda2iu8lqugl73m8hgeb83
cdk-stack.userPoolId = us-east-1_bVwFsBUGO
Stack ARN:
-arn:aws:cloudformation:us-east-1:676583371711:stack/cdk-stack/faf43800-9878-11ed-a070-0aacc64c8662
+arn:aws:cloudformation:us-east-1:XXXXXXXXXX:stack/cdk-stack/faf43800-9878-11ed-a070-0aacc64c8662
```
diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.js
index 5d9d6da3ee..df1730e22f 100644
--- a/packages/docs/sidebars.js
+++ b/packages/docs/sidebars.js
@@ -422,6 +422,7 @@ module.exports = {
items: ["lambda/without-iam/index", "lambda/without-iam/example"],
},
"lambda/serverless-framework-integration",
+ "lambda/aws-sqs-lambda-integration",
"lambda/optimizing-cost",
"lambda/optimizing-speed",
"lambda/limits",