Skip to content

🎥 Make videos programmatically with React

show lambdas currently in aws region

Jonny Burgerfb131327f3a4
diff --git a/packages/cli/src/index.tsx b/packages/cli/src/index.tsx
index 7914928826..be03bf2b32 100644
--- a/packages/cli/src/index.tsx
+++ b/packages/cli/src/index.tsx
@@ -5,7 +5,7 @@ import {Log} from './log';
import {parsedCli} from './parse-command-line';
import {previewCommand} from './preview';
import {printHelp} from './print-help';
-import {createProgressBar, makeProgressBar} from './progress-bar';
+import {createOverwriteableCliOutput, makeProgressBar} from './progress-bar';
import {render} from './render';
import {upgrade} from './upgrade';
@@ -37,7 +37,7 @@ export const cli = async () => {
export * from './render';
export const CliInternals = {
- createProgressBar,
+ createOverwriteableCliOutput,
chalk,
xns,
makeProgressBar,
diff --git a/packages/cli/src/progress-bar.ts b/packages/cli/src/progress-bar.ts
index d2ae982b7f..03f326cf1b 100644
--- a/packages/cli/src/progress-bar.ts
+++ b/packages/cli/src/progress-bar.ts
@@ -2,7 +2,7 @@
import ansiDiff from 'ansi-diff';
import chalk from 'chalk';
-export const createProgressBar = () => {
+export const createOverwriteableCliOutput = () => {
const diff = ansiDiff();
process.stdout.write('');
return {
diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsx
index d61df6ac58..2965382878 100644
--- a/packages/cli/src/render.tsx
+++ b/packages/cli/src/render.tsx
@@ -19,7 +19,7 @@ import {loadConfigFile} from './load-config';
import {Log} from './log';
import {parseCommandLine, parsedCli} from './parse-command-line';
import {
- createProgressBar,
+ createOverwriteableCliOutput,
makeBundlingProgress,
makeRenderingProgress,
makeStitchingProgres,
@@ -106,7 +106,7 @@ export const render = async () => {
}
const bundleStartTime = Date.now();
- const bundlingProgress = createProgressBar();
+ const bundlingProgress = createOverwriteableCliOutput();
const bundled = await bundle(
fullPath,
(progress) => {
@@ -154,7 +154,7 @@ export const render = async () => {
Log.verbose('Output dir', outputDir);
- const renderProgress = createProgressBar();
+ const renderProgress = createOverwriteableCliOutput();
let totalFrames = 0;
const renderStart = Date.now();
const {assetsInfo} = await renderFrames({
@@ -217,7 +217,7 @@ export const render = async () => {
throw new TypeError('CRF is unexpectedly not a number');
}
- const stitchingProgress = createProgressBar();
+ const stitchingProgress = createOverwriteableCliOutput();
stitchingProgress.update(
makeStitchingProgres({
diff --git a/packages/lambda/src/cleanup/cleanup-lambdas.ts b/packages/lambda/src/cleanup/cleanup-lambdas.ts
index 6a5e19a3c7..6846786285 100644
--- a/packages/lambda/src/cleanup/cleanup-lambdas.ts
+++ b/packages/lambda/src/cleanup/cleanup-lambdas.ts
@@ -3,35 +3,32 @@ import {
LambdaClient,
ListFunctionsCommand,
} from '@aws-sdk/client-lambda';
-import {CliInternals} from '@remotion/cli';
-import {REGION, RENDER_FN_PREFIX} from '../constants';
+import {RENDER_FN_PREFIX} from '../constants';
-export const cleanupLambdas = CliInternals.xns(
- async (
- lambdaClient: LambdaClient = new LambdaClient({
- region: REGION,
- })
- ) => {
- // TODO: Pagination
- // eslint-disable-next-line no-constant-condition
- while (true) {
- const lambdas = await lambdaClient.send(new ListFunctionsCommand({}));
+export const getRemotionLambdas = async (lambdaClient: LambdaClient) => {
+ const lambdas = await lambdaClient.send(new ListFunctionsCommand({}));
- const remotionLambdas = (lambdas.Functions || []).filter((f) =>
- f.FunctionName?.startsWith(RENDER_FN_PREFIX)
- );
- if (remotionLambdas.length === 0) {
- break;
- }
+ const remotionLambdas = (lambdas.Functions || []).filter((f) =>
+ f.FunctionName?.startsWith(RENDER_FN_PREFIX)
+ );
- for (const lambda of remotionLambdas) {
- console.log('Deleting lambda', lambda.FunctionName);
- await lambdaClient.send(
- new DeleteFunctionCommand({
- FunctionName: lambda.FunctionName,
- })
- );
- }
- }
+ return remotionLambdas;
+};
+
+export const cleanupLambdas = async (lambdaClient: LambdaClient) => {
+ const remotionLambdas = await getRemotionLambdas(lambdaClient);
+ if (remotionLambdas.length === 0) {
+ return;
+ }
+
+ for (const lambda of remotionLambdas) {
+ console.log('Deleting lambda', lambda.FunctionName);
+ await lambdaClient.send(
+ new DeleteFunctionCommand({
+ FunctionName: lambda.FunctionName,
+ })
+ );
}
-);
+
+ await cleanupLambdas(lambdaClient);
+};
diff --git a/packages/lambda/src/cli/cleanup.ts b/packages/lambda/src/cli/cleanup.ts
index ff0a53614a..8664b28297 100644
--- a/packages/lambda/src/cli/cleanup.ts
+++ b/packages/lambda/src/cli/cleanup.ts
@@ -1,25 +1,47 @@
import {CliInternals} from '@remotion/cli';
-import {s3Client} from '../aws-clients';
+import {lambdaClient, s3Client} from '../aws-clients';
import {chunk} from '../chunk';
+import {getRemotionLambdas} from '../cleanup/cleanup-lambdas';
import {getRemotionS3Buckets} from '../cleanup/s3-buckets';
import {REGION} from '../constants';
import {Log} from './log';
export const cleanupCommand = async () => {
- Log.info('Fetching AWS account...');
- const {remotionBuckets} = await getRemotionS3Buckets(s3Client);
- Log.info(
- `Your AWS account in ${REGION} contains the following Remotion-related resources:`
+ const fetching = CliInternals.createOverwriteableCliOutput();
+ fetching.update('Fetching AWS account...');
+
+ const [{remotionBuckets}, lambdas] = await Promise.all([
+ getRemotionS3Buckets(s3Client),
+ getRemotionLambdas(lambdaClient),
+ ]);
+
+ fetching.update(
+ `Your AWS account in ${REGION} contains the following Remotion-related resources:\n\n`
);
Log.info(
`${remotionBuckets.length} ${
remotionBuckets.length === 1 ? 'bucket' : 'buckets'
}:`
);
+ if (remotionBuckets.length !== 0) {
+ Log.info(
+ `${chunk(remotionBuckets, 2)
+ .map((b) =>
+ CliInternals.chalk.blue(b.map((a) => a.padEnd(40, ' ')).join(' '))
+ )
+ .join('\n')}`
+ );
+
+ Log.info();
+ }
+
+ Log.info(`${lambdas.length} ${lambdas.length === 1 ? 'lambda' : 'lambdas'}:`);
Log.info(
- `${chunk(remotionBuckets, 2)
+ `${chunk(lambdas, 2)
.map((b) =>
- CliInternals.chalk.blue(b.map((a) => a.padEnd(40, ' ')).join(' '))
+ CliInternals.chalk.blue(
+ b.map((a) => (a.FunctionName ?? '').padEnd(40, ' ')).join(' ')
+ )
)
.join('\n')}`
);
diff --git a/packages/lambda/src/cli/deploy.ts b/packages/lambda/src/cli/deploy.ts
index aade542cfe..85049f7d72 100644
--- a/packages/lambda/src/cli/deploy.ts
+++ b/packages/lambda/src/cli/deploy.ts
@@ -41,7 +41,7 @@ export const deployCommand = async () => {
process.exit(1);
}
- const progressBar = CliInternals.createProgressBar();
+ const progressBar = CliInternals.createOverwriteableCliOutput();
const multiProgress: {
bundleProgress: BundleProgress;
diff --git a/packages/lambda/src/run.ts b/packages/lambda/src/run.ts
index 523db62e0e..7b3e816b9d 100644
--- a/packages/lambda/src/run.ts
+++ b/packages/lambda/src/run.ts
@@ -1,5 +1,5 @@
import {CliInternals} from '@remotion/cli';
-import {s3Client} from './aws-clients';
+import {lambdaClient, s3Client} from './aws-clients';
import {callLambda} from './call-lambda';
import {checkLambdaStatus} from './check-lambda-status';
import {cleanupLambdas} from './cleanup/cleanup-lambdas';
@@ -9,7 +9,7 @@ import {createLambda} from './create-lambda';
import {sleep} from './sleep';
CliInternals.xns(async () => {
- await cleanupLambdas();
+ await cleanupLambdas(lambdaClient);
await cleanUpBuckets(s3Client);
const {functionName, bucketUrl} = await createLambda();