Skip to content

πŸŽ₯ Make videos programmatically with React

implement layout of the article

Alex Fernandezb707ad1bedc8
diff --git a/packages/docs/docs/lambda/ec2.md b/packages/docs/docs/lambda/ec2.md
index e29b2b3727..f1f74db6dc 100644
--- a/packages/docs/docs/lambda/ec2.md
+++ b/packages/docs/docs/lambda/ec2.md
@@ -1,32 +1,27 @@
---
-image: /generated/articles-docs-lambda-sqs.png
-title: Using Lambda with SQS
+title: Using Lambda with EC2
slug: /lambda/sqs
-sidebar_label: Queueing with SQS
+sidebar_label: Lambda rendering from ec2
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/) (Simple Queue Service) and Remotion's [`renderMediaOnLambda()`](/docs/lambda/rendermediaonlambda) API.
+This guide will show you how to trigger Remotion's [`renderMediaOnLambda()`](/docs/lambda/rendermediaonlambda) API from AWS ec2 instance from NodeJS and Typescript.
-Queues are used to park requests to make way for the underlying resources to cope up demand. Since AWS Lambda is subject to a [concurrency limit](/docs/lambda/troubleshooting/rate-limit), you can use SQS to queue renders in the background and you notify the user when the render process is completed by sending them an email or using other 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 as from the [Serverless Framework guide](/docs/lambda/serverless-framework-integration).
-- The [apigw-sqs-app](https://github.com/alexfernandez803/remotion-serverless/tree/main/apigw-sqs-app) (API Gateway SQS) 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 JSON data sent by the user; this can be an input payload for the Remotion Lambda function. 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, processes it and renders videos.
+- The [ec2-remotion-lambda](https://github.com/alexfernandez803/remotion-serverless/tree/main/ec2-remotion-lambda).
-The `enqueue-function` is configured to be invoked through [API Gateway](https://aws.amazon.com/api-gateway/) and is 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 guide 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).
## remotion-app
- Follow the same setup instruction from [remotion-app guide](/docs/lambda/serverless-framework-integration#remotion-app) as we will just re-use the application.
-## apigw-sqs-app
+## ec2-remotion-lambda
In the following step, the Lambda functions [`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) will be deployed to your AWS account. This guide is designed to be executed on your local machine.
@@ -40,296 +35,38 @@ The project will create all the resources defined by the CDK stack, including se
### 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
+#### 1. 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"
- ),
- ],
-});
-```
+#### 2. Create a role for the ec2 instance
-This creates a role in AWS with the name of `remotionSQSLambdaRole` with 2 policies attached:
+#### Steps
+- 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
-- `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 order to render a video. This policy is exactly the same policy from this [guide](/docs/lambda/without-iam/#1-create-role-policy).
+Add a policy statement similar to the one below, which is defining the bucket Lambda needs to transfer the rendered video to.
-#### 5. Optional - Synthesize
-From the `apigw-sqs-app` directory, execute the `cdk synthesize` command.
+#### 3. Trust the ec2 role from remotion role
-```bash
-cdk synthesize
-```
+#### 4. Deploy the applicatiion to the ec2
-This command will show the [CloudFormation Template](https://aws.amazon.com/cloudformation/) that CDK will execute to your AWS account.
+#### 4. Assign the ec2 role from ec2
#### 6. Deploy the apigw-sqs-app project
-From the `apigw-sqs-app` directory, execute the `cdk deploy` command.
-
-```bash
-cdk deploy
-```
-
-This will orchestrate the generation of resources defined in the CDK stack, which are CloudFormation templates in the background.
-
-```bash title="Deploy output"
- 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 variables 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
-```
-
-### Combining API Gateway, Remotion Lambda and SQS together.
-
-These are important information on how IAM roles are used by the function and instructions to enable the [render-lambda-function](https://github.com/alexfernandez803/remotion-serverless/blob/main/apigw-sqs-app/lib/remotion-cdk-starter-stack.ts#L97) to consume SQS messages.
-
-From [CDK stack code](https://github.com/alexfernandez803/remotion-serverless/blob/main/apigw-sqs-app/lib/remotion-cdk-starter-stack.ts#L64), here are the important parts to take note of.
-
-- The stack creates a queue named `remotion_queue`.
-
-```js 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. Each individual role are assigned to their respective Lambda function.
-
- ```js 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), to allow it to write CloudWatch logs.
-
- ```js 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"
- ),
- ],
- });
- ```
-
-- The [`render-lambda-function`](https://github.com/alexfernandez803/remotion-serverless/blob/main/apigw-sqs-app/lib/remotion-cdk-starter-stack.ts#L97) has been assigned this role, which includes access to interact with Cloudwatch and permission to access other AWS services as specified in the `remotion-executionrole-policy`.
-
- ```js title="Grant access to the queue"
- // πŸ‘‡ Grant permission to publish to the queue
- remotionQueue.grantSendMessages(apiIntegrationRole);
- // πŸ‘‡ grant permission to consume messages from the queue
- remotionQueue.grantConsumeMessages(renderFunctionLambdaRole);
- ```
-
-- Allow the render function to listen to the queue.
-
- ```js 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:
@@ -341,30 +78,9 @@ From the guide, `YOUR_USER_POOL_CLIENT_ID` is `apigw-sqs-app-stack.userPoolClien
The base API URL has the format of `https://25w651t09g.execute-api.ap-southeast-2.amazonaws.com/dev/enqueue` from the output `apigw-sqs-app-stack.apiUrl`.
-#### Trigger a video generation request
-
-```bash title="render video"
-curl --location --request POST 'https://xxxxxxxx.execute-api.ap-southeast-2.amazonaws.com/dev/enqueue' \
---header 'Authorization: Bearer eyJraWQiOiJMVVVVZGtIQ1JXWEEyWEEXXXXXXXXXjMKR1t5S-oA' \
---data-raw '{
- "message": "Hello"
-}'
-```
-
-```bash title="response"
-{
- {"message":"Message Send to SQS- Here is MessageId: a6abd0bc-b838-48b5-a562-4c511fac5b2f"}
-}
-```
-
-This will initiate the render request of a video by taking the JSON and putting it in the queue.
-On the other end, [`render-lambda-function`](https://github.com/alexfernandez803/remotion-serverless/blob/main/apigw-sqs-app/src/render-lambda-function/index.ts) will be notified by SQS that is a video render request, it will consume the data from the render request and generate the video as per instruction, the function executes [`renderMediaOnLambda()`](/docs/lambda/rendermediaonlambda) as part of the process.
-
## 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).
-- The deployment of `apigw-sqs-app` is configured to be deployed at `ap-southeast-2` region to simplify the project, adjust this in the code at [`remotion-cdk-starter.ts`](https://github.com/alexfernandez803/remotion-serverless/blob/main/apigw-sqs-app/bin/remotion-cdk-starter.ts).
-- Remotion packages should be bundled inside the function when deployed, you can this in `nodeModules` property from `bundling` object, the code for this located in [here](https://github.com/alexfernandez803/remotion-serverless/blob/main/apigw-sqs-app/lib/remotion-cdk-starter-stack.ts#L103).
+-
## See also