🎥 Make videos programmatically with React
create lambda based on account id
Jonny Burger66cdfdf2f91f
diff --git a/packages/docs/docs/lambda-setup.md b/packages/docs/docs/lambda-setup.mdnew file mode 100644index 0000000000..fc23941d70--- /dev/null+++ b/packages/docs/docs/lambda-setup.md@@ -0,0 +1,73 @@+---+id: Lambda setup+title: Lambda setup+---++## 1. Install `@remotion/lambda`++```+npm i @remotion/lambda+```++## 2. Create role policy++- Go to AWS account IAM section+- Create a new policy+- Click on JSON+- Type in `npx remotion-lambda policies role` and copy it into the JSON field+- Go to tags, no tags are needed+- Give the policy the name `remotion-lambda-policy`!++## 3. Create a role++- Go to AWS account IAM section+- Create a new role+- Use case: Select `Lambda`+- Click next+- Attach permissions role: `remotion-lambda-policy`+- Permissions boundary: Skip it+- Tags: Skip it+- Role name: Name it `remotion-lambda-role` exactly!++## 4. Create an user++- Click `Create user`+- Select any username+- Programmatic access = YES+- Management console access = NO+- Click next+- Tags: Skip+- Click "Create user"+- Copy Access key ID and Secret Access Key+- Add a `.env` file to your project++```dotenv+AWS_ACCESS_KEY_ID=xxxxxx+AWS_SECRET_ACCESS_KEY=xxx++```++## 5. Add permissions to your user++- Click on your user+- Click "Add inline policy"+- Click JSON+- Enter in your terminal: `npx remotion-lambda policies user` and copy it in+- Give the policy a name, can be anything+- Click "Create policy"++## 6. Optional: Validate the permission setup++- Run `npx remotion-lambda policies validate`++## 7. Deploy a lambda++- Run `npx remotion-lambda deploy`++## 8. Deploy a website++- Run `npx remotion-lambda upload`++## 9. Render a video++- Run `npx remotion-lambda render <serve-url> <composition-name>`diff --git a/packages/lambda/src/create-lambda.ts b/packages/lambda/src/create-lambda.tsindex 5e8d418df2..a05b19dc8d 100644--- a/packages/lambda/src/create-lambda.ts+++ b/packages/lambda/src/create-lambda.ts@@ -1,5 +1,7 @@+import {GetUserCommand} from '@aws-sdk/client-iam';import {CreateFunctionCommand, LambdaClient} from '@aws-sdk/client-lambda';import {readFileSync} from 'fs';+import {iamClient} from './aws-clients';import {bundleLambda} from './bundle-lambda';import {EFS_MOUNT_PATH,@@ -26,6 +28,14 @@ export const createLambda = async () => {const renderOut = await bundleLambda('render');console.log('done Bundling');+ const user = await iamClient.send(new GetUserCommand({}));++ const accountId = user.User?.Arn?.match(/aws:iam::([0-9]+)/);++ if (!accountId) {+ throw new Error('Cannot get account ID');+ }+const created = await lambdaClient.send(new CreateFunctionCommand({Code: {@@ -33,13 +43,12 @@ export const createLambda = async () => {},FunctionName: fnNameRender,Handler: 'index.handler',- Role:- developer === 'shankhadeep'- ? 'arn:aws:iam::363307378317:role/awesomeLambda'- : 'arn:aws:iam::976210361945:role/remotion-role', // IAM_ROLE_ARN; e.g., arn:aws:iam::650138640062:role/v3-lambda-tutorial-lambda-role+ // TODO: Give helpful suggestion if user did not create role+ Role: `arn:aws:iam::${accountId[1]}:role/remotion-lambda-role`,Runtime: 'nodejs14.x',Description: 'Renders a Remotion video.',MemorySize: MEMORY_SIZE,+ // TODO: Set timeoutTimeout: 120,Layers: [layerArn],@@ -70,6 +79,7 @@ export const createLambda = async () => {: undefined,}));+console.log('lambdas created');if (!created.FunctionName) {