Skip to content

🎥 Make videos programmatically with React

start custom role ARN

Jonny Burger2c016f6b24db
diff --git a/packages/lambda/src/api/create-function.ts b/packages/lambda/src/api/create-function.ts
index 5309283701..d0bdd39b14 100644
--- a/packages/lambda/src/api/create-function.ts
+++ b/packages/lambda/src/api/create-function.ts
@@ -26,6 +26,7 @@ export const createFunction = async ({
retentionInDays,
architecture,
ephemerealStorageInMb,
+ customRoleArn,
}: {
createCloudWatchLogGroup: boolean;
region: AwsRegion;
@@ -38,6 +39,7 @@ export const createFunction = async ({
retentionInDays: number;
ephemerealStorageInMb: number;
architecture: LambdaArchitecture;
+ customRoleArn?: string;
}): Promise<{FunctionName: string}> => {
if (createCloudWatchLogGroup) {
try {
@@ -65,6 +67,18 @@ export const createFunction = async ({
return {FunctionName: functionName};
}
+ if (
+ typeof customRoleArn !== 'undefined' &&
+ typeof customRoleArn !== 'string'
+ ) {
+ throw new TypeError(
+ 'A custom role ARN must either be "undefined" or a string, but instead got: ' +
+ JSON.stringify(customRoleArn)
+ );
+ }
+
+ const defaultRoleName = `arn:aws:iam::${accountId}:role/${ROLE_NAME}`;
+
const {FunctionName} = await getLambdaClient(region).send(
new CreateFunctionCommand({
Code: {
@@ -72,7 +86,7 @@ export const createFunction = async ({
},
FunctionName: functionName,
Handler: 'index.handler',
- Role: `arn:aws:iam::${accountId}:role/${ROLE_NAME}`,
+ Role: customRoleArn ?? defaultRoleName,
Runtime: 'nodejs14.x',
Description: 'Renders a Remotion video.',
MemorySize: memorySizeInMb,
diff --git a/packages/lambda/src/cli/args.ts b/packages/lambda/src/cli/args.ts
index 174c390d31..c42b0f9069 100644
--- a/packages/lambda/src/cli/args.ts
+++ b/packages/lambda/src/cli/args.ts
@@ -24,6 +24,7 @@ type LambdaCommandLineOptions = {
['frames-per-lambda']: number;
['out-name']: string | undefined;
['architecture']: LambdaArchitecture;
+ ['custom-role-arn']: string | undefined;
privacy: Privacy;
};
diff --git a/packages/lambda/src/cli/index.ts b/packages/lambda/src/cli/index.ts
index 24209c0043..027675c3bc 100644
--- a/packages/lambda/src/cli/index.ts
+++ b/packages/lambda/src/cli/index.ts
@@ -1,5 +1,6 @@
import {CliInternals} from '@remotion/cli';
import {ROLE_NAME} from '../api/iam-validation/suggested-policy';
+import {BINARY_NAME} from '../defaults';
import {checkCredentials} from '../shared/check-credentials';
import {DOCS_URL} from '../shared/docs-url';
import {parsedLambdaCli} from './args';
@@ -118,6 +119,18 @@ export const executeCommand = async (args: string[]) => {
'The role defined for the function cannot be assumed by Lambda'
)
) {
+ if (parsedLambdaCli['custom-role-arn']) {
+ Log.error(
+ `
+ The role "${parsedLambdaCli['custom-role-arn']}" does not exist or has the wrong policy assigned to it. Do either:
+ - Remove the "--custom-role-arn" parameter and set up Remotion Lambda according to the setup guide
+ - Make sure the role has the same policy assigned as the one returned by "npx ${BINARY_NAME} ${POLICIES_COMMAND} ${ROLE_SUBCOMMAND}"
+
+ Revisit ${DOCS_URL}/docs/lambda/setup and make sure you set up the role and role policy correctly. Also see the troubleshooting page: ${DOCS_URL}/docs/lambda/troubleshooting/permissions. The original error message is:
+ `.trim()
+ );
+ }
+
Log.error(
`
The role "${ROLE_NAME}" does not exist in your AWS account or has the wrong policy assigned to it. Common reasons: