🎥 Make videos programmatically with React
better permissions error messages
Jonny Burgerd90aef11bad5
diff --git a/packages/lambda/src/cli/index.ts b/packages/lambda/src/cli/index.tsindex 0657268464..cf70734e87 100644--- a/packages/lambda/src/cli/index.ts+++ b/packages/lambda/src/cli/index.ts@@ -13,6 +13,7 @@ import {sitesCommand, SITES_COMMAND} from './commands/sites';import {stillCommand, STILL_COMMAND} from './commands/still';import {printHelp} from './help';import {quit} from './helpers/quit';+import {setIsCli} from './is-cli';import {Log} from './log';const requiresCredentials = (args: string[]) => {@@ -103,6 +104,7 @@ const matchCommand = async (args: string[]) => {export const executeCommand = async (args: string[]) => {try {+ setIsCli(true);await matchCommand(args);} catch (err) {const error = err as Error;diff --git a/packages/lambda/src/cli/is-cli.ts b/packages/lambda/src/cli/is-cli.tsnew file mode 100644index 0000000000..d62d3ff01b--- /dev/null+++ b/packages/lambda/src/cli/is-cli.ts@@ -0,0 +1,7 @@+let isCli = false;++export const getIsCli = () => isCli;++export const setIsCli = (cli: boolean) => {+ isCli = cli;+};diff --git a/packages/lambda/src/shared/check-credentials.ts b/packages/lambda/src/shared/check-credentials.tsindex c1a717fec6..0d2d8b0fb3 100644--- a/packages/lambda/src/shared/check-credentials.ts+++ b/packages/lambda/src/shared/check-credentials.ts@@ -1,21 +1,38 @@+import {Internals} from 'remotion';+import {getIsCli} from '../cli/is-cli';import {DOCS_URL} from './docs-url';-const messageForVariable = (variable: string) =>- `You have tried to call a Remotion Lambda function, but have not set the environment variable ${variable}. Please refer to the Remotion Lambda docs (${DOCS_URL}/docs/lambda/setup) to see how to generate the credentials for your AWS account and then set the environment variables. Environment variables from a '.env' file are not automatically read if you are calling the Node.JS APIs, in that case you need to read the .env file yourself using the 'dotenv' package.`;+const messageForVariable = (variable: string) => {+ return [+ `You have tried to call a Remotion Lambda function, but have not set the environment variable ${variable}.`,+ getIsCli()+ ? null+ : `- Environment variables from a '.env' file are not automatically read if you are calling the Node.JS APIs, in that case you need to load the file yourself or set the environment variables manually.`,+ `- Please refer to the Remotion Lambda docs (${DOCS_URL}/docs/lambda/setup) to see how to generate the credentials for your AWS account and then set the environment variables.`,+ `- For more reasons see the troubleshooting page: ${DOCS_URL}/docs/lambda/troubleshooting/permissions`,+ ]+ .filter(Internals.truthy)+ .join('\n');+};-// TODO: Could better differentiate between CLI and Node.JS acccess.export const checkCredentials = () => {if (!process.env.AWS_ACCESS_KEY_ID &&!process.env.REMOTION_AWS_ACCESS_KEY_ID) {- throw new Error(messageForVariable('AWS_ACCESS_KEY_ID'));+ throw new Error(+ messageForVariable('AWS_ACCESS_KEY_ID or REMOTION_AWS_ACCESS_KEY_ID')+ );}if (!process.env.AWS_SECRET_ACCESS_KEY &&!process.env.REMOTION_AWS_SECRET_ACCESS_KEY) {- throw new Error(messageForVariable('AWS_SECRET_ACCESS_KEY'));+ throw new Error(+ messageForVariable(+ 'AWS_SECRET_ACCESS_KEY or REMOTION_AWS_SECRET_ACCESS_KEY'+ )+ );}};