Skip to content

🎥 Make videos programmatically with React

validate credentials

Jonny Burgerb1a1a71543e0
diff --git a/packages/lambda/src/api/get-deployed-lambdas.ts b/packages/lambda/src/api/get-deployed-lambdas.ts
index af6560d490..beee78bbb7 100644
--- a/packages/lambda/src/api/get-deployed-lambdas.ts
+++ b/packages/lambda/src/api/get-deployed-lambdas.ts
@@ -3,6 +3,7 @@ import {AwsRegion} from '../pricing/aws-regions';
import {getLambdaClient} from '../shared/aws-clients';
import {RENDER_FN_PREFIX} from '../shared/constants';
+// TODO: Should assert string
export const getDeployedLambdas = async (options: {region: AwsRegion}) => {
const lambdas = await getLambdaClient(options.region).send(
new ListFunctionsCommand({})
diff --git a/packages/lambda/src/cli/index.ts b/packages/lambda/src/cli/index.ts
index 61d809264c..ad5adb7cbf 100644
--- a/packages/lambda/src/cli/index.ts
+++ b/packages/lambda/src/cli/index.ts
@@ -1,4 +1,5 @@
import {CliInternals} from '@remotion/cli';
+import {checkCredentials} from '../shared/check-credentials';
import {parsedLambdaCli} from './args';
import {cleanupCommand, CLEANUP_COMMAND} from './cleanup';
import {functionsCommand, FUNCTIONS_COMMAND} from './commands/functions';
@@ -9,6 +10,7 @@ import {Log} from './log';
import {renderCommand, RENDER_COMMAND} from './render';
const matchCommand = async () => {
+ checkCredentials();
if (parsedLambdaCli.help || parsedLambdaCli._.length === 0) {
printHelp();
process.exit(0);
diff --git a/packages/lambda/src/shared/aws-clients.ts b/packages/lambda/src/shared/aws-clients.ts
index 865d9a6fb3..4a8d5cd3b9 100644
--- a/packages/lambda/src/shared/aws-clients.ts
+++ b/packages/lambda/src/shared/aws-clients.ts
@@ -2,6 +2,7 @@ import {IAMClient} from '@aws-sdk/client-iam';
import {LambdaClient} from '@aws-sdk/client-lambda';
import {S3Client} from '@aws-sdk/client-s3';
import {AwsRegion} from '../pricing/aws-regions';
+import {checkCredentials} from './check-credentials';
const _s3Clients: Partial<Record<AwsRegion, S3Client>> = {};
const _lambdaClients: Partial<Record<AwsRegion, LambdaClient>> = {};
@@ -9,6 +10,7 @@ const _iamClients: Partial<Record<AwsRegion, IAMClient>> = {};
export const getS3Client = (region: AwsRegion) => {
if (!_s3Clients[region]) {
+ checkCredentials();
_s3Clients[region] = new S3Client({region});
}
@@ -17,6 +19,7 @@ export const getS3Client = (region: AwsRegion) => {
export const getLambdaClient = (region: AwsRegion) => {
if (!_lambdaClients[region]) {
+ checkCredentials();
_lambdaClients[region] = new LambdaClient({region});
}
@@ -25,6 +28,7 @@ export const getLambdaClient = (region: AwsRegion) => {
export const getIamClient = (region: AwsRegion) => {
if (!_iamClients[region]) {
+ checkCredentials();
_iamClients[region] = new IAMClient({region});
}
diff --git a/packages/lambda/src/shared/check-credentials.ts b/packages/lambda/src/shared/check-credentials.ts
new file mode 100644
index 0000000000..f2650e2b41
--- /dev/null
+++ b/packages/lambda/src/shared/check-credentials.ts
@@ -0,0 +1,13 @@
+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 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.`;
+
+// TODO: Could better differentiate between CLI and Node.JS acccess.
+export const checkCredentials = () => {
+ if (!process.env.AWS_ACCESS_KEY_ID) {
+ throw new Error(messageForVariable('AWS_ACCESS_KEY_ID'));
+ }
+
+ if (!process.env.AWS_SECRET_ACCESS_KEY) {
+ throw new Error(messageForVariable('AWS_SECRET_ACCESS_KEY'));
+ }
+};