Skip to content

🎥 Make videos programmatically with React

feat: include example render execution

Alex Fernandezf7a6c7ff23aa
diff --git a/packages/example-lambda/lib/example-lambda-stack.ts b/packages/example-lambda/lib/example-lambda-stack.ts
index 0cbaa16274..25c7e0c0a0 100644
--- a/packages/example-lambda/lib/example-lambda-stack.ts
+++ b/packages/example-lambda/lib/example-lambda-stack.ts
@@ -1,29 +1,20 @@
import * as cdk from "aws-cdk-lib";
import { Construct } from "constructs";
import * as lambda from "aws-cdk-lib/aws-lambda";
+import { UserPool } from "aws-cdk-lib/aws-cognito";
+
import {
LambdaIntegration,
LambdaRestApi,
+ CfnAuthorizer,
TokenAuthorizer,
+ AuthorizationType,
} from "aws-cdk-lib/aws-apigateway";
export class ExampleLambdaStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
- /**
- const authorizerFn = new lambda.Function(this, "BasicAuthAuthorizer", {
- runtime: lambda.Runtime.NODEJS_14_X,
- code: lambda.Code.fromAsset("authorizer"),
- handler: "authorizer.handler",
- });
-
- const authorizer = new TokenAuthorizer(this, "CustomBasicAuthAuthorizer", {
- handler: authorizerFn,
- identitySource: "method.request.header.Authorization",
- });
-
- */
const remotionLambda = new lambda.Function(this, "RemotionLambdaHandler", {
runtime: lambda.Runtime.NODEJS_14_X,
code: lambda.Code.fromAsset("resources"),
@@ -40,8 +31,23 @@ export class ExampleLambdaStack extends cdk.Stack {
}
);
- const renderAPI = RemotionLambdaRestApi.root.addResource("render");
+ // Cognito User Pool with Email Sign-in Type.
+ const userPool = new UserPool(this, "userPool", {
+ signInAliases: {
+ email: true,
+ },
+ });
+ // Authorizer for the Hello World API that uses the
+ // Cognito User pool to Authorize users.
+ const authorizer = new CfnAuthorizer(this, "cfnAuth", {
+ restApiId: RemotionLambdaRestApi.restApiId,
+ name: "RemotionLambdaRestApi",
+ type: "COGNITO_USER_POOLS",
+ identitySource: "method.request.header.Authorization",
+ providerArns: [userPool.userPoolArn],
+ });
+ const renderAPI = RemotionLambdaRestApi.root.addResource("render");
renderAPI.addMethod("POST", new LambdaIntegration(remotionLambda), {});
}
}
diff --git a/packages/example-lambda/resources/render_function.ts b/packages/example-lambda/resources/render_function.ts
index 3b53ac4c3e..265dfdd700 100644
--- a/packages/example-lambda/resources/render_function.ts
+++ b/packages/example-lambda/resources/render_function.ts
@@ -1,14 +1,22 @@
import { Handler } from "aws-lambda";
+import { renderMediaOnLambda } from "@remotion/lambda/client";
export const handler: Handler = async (event: any = {}): Promise<any> => {
- //console.log(event);
-
- //return { statusCode: 201, body: "Hello world!" };
+ 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",
+ });
return {
statusCode: 200,
body: JSON.stringify({
- message: "success",
+ isSuccess: true,
+ bucketName,
+ renderId,
}),
};
};