🎥 Make videos programmatically with React
delete function
Jonny Burgerd7adb05c6210
diff --git a/packages/lambda/src/cleanup/cleanup-lambdas.ts b/packages/lambda/src/cleanup/cleanup-lambdas.tsindex 31e9631de4..5a9222e1e6 100644--- a/packages/lambda/src/cleanup/cleanup-lambdas.ts+++ b/packages/lambda/src/cleanup/cleanup-lambdas.ts@@ -1,42 +1,29 @@-import {- DeleteFunctionCommand,- LambdaClient,- ListFunctionsCommand,-} from '@aws-sdk/client-lambda';-import {RENDER_FN_PREFIX} from '../shared/constants';--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)- );-- return remotionLambdas;-};+import {AwsRegion} from '..';+import {deleteFunction} from '../api/delete-function';+import {getFunctions} from '../api/get-functions';export const cleanupLambdas = async ({- lambdaClient,onBeforeDelete,onAfterDelete,+ region,}: {- lambdaClient: LambdaClient;+ region: AwsRegion;onBeforeDelete?: (lambdaName: string) => void;onAfterDelete?: (lambdaName: string) => void;}) => {- const remotionLambdas = await getRemotionLambdas(lambdaClient);+ const remotionLambdas = await getFunctions({region, compatibleOnly: false});if (remotionLambdas.length === 0) {return;}for (const lambda of remotionLambdas) {- onBeforeDelete?.(lambda.FunctionName as string);- await lambdaClient.send(- new DeleteFunctionCommand({- FunctionName: lambda.FunctionName,- })- );- onAfterDelete?.(lambda.FunctionName as string);+ onBeforeDelete?.(lambda.name);+ await deleteFunction({+ region,+ functionName: lambda.name,+ });+ onAfterDelete?.(lambda.name);}- await cleanupLambdas({lambdaClient, onBeforeDelete, onAfterDelete});+ await cleanupLambdas({region, onBeforeDelete, onAfterDelete});};diff --git a/packages/lambda/src/cli/cleanup.ts b/packages/lambda/src/cli/cleanup.tsindex c7be809b1a..d3dcb84847 100644--- a/packages/lambda/src/cli/cleanup.ts+++ b/packages/lambda/src/cli/cleanup.ts@@ -1,10 +1,9 @@-import {LambdaClient} from '@aws-sdk/client-lambda';import {CliInternals} from '@remotion/cli';import {getRemotionS3Buckets} from '../api/get-buckets';-import {cleanupLambdas, getRemotionLambdas} from '../cleanup/cleanup-lambdas';+import {getFunctions} from '../api/get-functions';+import {cleanupLambdas} from '../cleanup/cleanup-lambdas';import {cleanUpBuckets} from '../cleanup/s3-buckets';import {AwsRegion} from '../pricing/aws-regions';-import {getLambdaClient} from '../shared/aws-clients';import {chunk} from '../shared/chunk';import {BINARY_NAME} from '../shared/constants';import {getAwsRegion} from './get-aws-region';@@ -14,9 +13,9 @@ export const CLEANUP_COMMAND = 'cleanup';export const CLEANUP_LAMBDAS_SUBCOMMAND = 'lambdas';const CLEANUP_S3_BUCKETS_SUBCOMMAND = 'buckets';-const cleanupLambdaCommand = async (client: LambdaClient) => {+const cleanupLambdaCommand = async (region: AwsRegion) => {await cleanupLambdas({- lambdaClient: client,+ region,onAfterDelete: (lambdaName: string) =>Log.info(CliInternals.chalk.blue(`Deleted ${lambdaName}`)),});@@ -42,7 +41,7 @@ const cleanupBucketsCommand = async (region: AwsRegion) => {export const cleanupCommand = async (args: string[]) => {const region = getAwsRegion();if (args[0] === CLEANUP_LAMBDAS_SUBCOMMAND) {- await cleanupLambdaCommand(getLambdaClient(getAwsRegion()));+ await cleanupLambdaCommand(getAwsRegion());return;}@@ -56,7 +55,7 @@ export const cleanupCommand = async (args: string[]) => {const [{remotionBuckets}, lambdas] = await Promise.all([getRemotionS3Buckets(region),- getRemotionLambdas(getLambdaClient(region)),+ getFunctions({region, compatibleOnly: false}),]);if (remotionBuckets.length === 0 && lambdas.length === 0) {fetching.update(@@ -100,7 +99,7 @@ export const cleanupCommand = async (args: string[]) => {`${chunk(lambdas, 2).map((b) =>CliInternals.chalk.blue(- b.map((a) => (a.FunctionName ?? '').padEnd(40, ' ')).join(' ')+ b.map((a) => (a.name ?? '').padEnd(40, ' ')).join(' '))).join('\n')}`diff --git a/packages/lambda/src/run.ts b/packages/lambda/src/run.tsindex 532f42f0e1..970345370b 100644--- a/packages/lambda/src/run.ts+++ b/packages/lambda/src/run.ts@@ -4,14 +4,14 @@ import {deployFunction} from './api/deploy-function';import {deployProject} from './api/deploy-project';import {ensureLambdaBinaries} from './api/ensure-lambda-binaries';import {getRemotionS3Buckets} from './api/get-buckets';+import {getFunctions} from './api/get-functions';import {getOrCreateBucket} from './api/get-or-create-bucket';import {getRenderProgress} from './api/get-render-progress';-import {cleanupLambdas, getRemotionLambdas} from './cleanup/cleanup-lambdas';+import {cleanupLambdas} from './cleanup/cleanup-lambdas';import {getAwsRegion} from './cli/get-aws-region';import {Log} from './cli/log';import {lambdaLs} from './functions/helpers/io';import {AwsRegion} from './pricing/aws-regions';-import {getLambdaClient} from './shared/aws-clients';import {callLambda} from './shared/call-lambda';import {getSitesKey,@@ -32,7 +32,7 @@ const getFnName = async (options: {}> => {const {bucketName} = await getOrCreateBucket({region: getAwsRegion()});if (DEPLOY) {- await cleanupLambdas({lambdaClient: getLambdaClient(options.region)});+ await cleanupLambdas({region: options.region});// await cleanUpBuckets({s3client: s3Client});const {layerArn} = await ensureLambdaBinaries(getAwsRegion());@@ -52,7 +52,10 @@ const getFnName = async (options: {return {functionName, bucketUrl: url, compositionName: 'my-video'};}- const lambdas = await getRemotionLambdas(getLambdaClient(options.region));+ const lambdas = await getFunctions({+ region: options.region,+ compatibleOnly: true,+ });const {remotionBuckets} = await getRemotionS3Buckets(options.region);const websiteBuckets = remotionBuckets.filter((b) =>(b.Name as string).startsWith(REMOTION_BUCKET_PREFIX)@@ -66,7 +69,7 @@ const getFnName = async (options: {});const firstSite = firstBucket.find(() => true);return {- functionName: lambdas[0].FunctionName as string,+ functionName: lambdas[0].name as string,bucketUrl: makeS3Url({bucketName: websiteBuckets[0].Name as string,subFolder: firstSite?.Key?.match(/(sites\/.*)\//)?.[1] as string,