Skip to content

🎥 Make videos programmatically with React

sites rmall command

Jonny Burgerf8825e0337f4
diff --git a/packages/docs/docs/lambda/cli/sites.md b/packages/docs/docs/lambda/cli/sites.md
index 744d01c42c..d5487824ae 100644
--- a/packages/docs/docs/lambda/cli/sites.md
+++ b/packages/docs/docs/lambda/cli/sites.md
@@ -188,6 +188,14 @@ Removes a site without asking for confirmation.
npx remotion lambda sites rm abcdef -y
```
+## rmall
+
+Remove all sites in the selected AWS region.
+
+```bash
+npx remotion lambda sites rmall
+```
+
<details>
<summary>
Example output
@@ -241,6 +249,14 @@ Example output
</pre>
</details>
-:::tip
-With the `npx remotion lambda sites rm -f $(npx remotion lambda sites ls -q)` command, you can delete all your sites at once (on most UNIX shells like `zsh`).
-:::
+### `--region`
+
+The [AWS region](/docs/lambda/region-selection) to select. Both project and function should be in this region.
+
+### `--yes`, `-y`
+
+Removes all sites without asking for confirmation.
+
+```
+npx remotion lambda sites rmall -y
+```
diff --git a/packages/lambda/src/cli/commands/sites/index.ts b/packages/lambda/src/cli/commands/sites/index.ts
index 6baaa3da09..ce3935eb8d 100644
--- a/packages/lambda/src/cli/commands/sites/index.ts
+++ b/packages/lambda/src/cli/commands/sites/index.ts
@@ -5,6 +5,7 @@ import {quit} from '../../helpers/quit';
import {sitesCreateSubcommand, SITES_CREATE_SUBCOMMAND} from './create';
import {sitesLsSubcommand, SITES_LS_SUBCOMMAND} from './ls';
import {sitesRmSubcommand, SITES_RM_COMMAND} from './rm';
+import {sitesRmallSubcommand, SITES_RMALL_COMMAND} from './rmall';
export const SITES_COMMAND = 'sites';
@@ -36,6 +37,10 @@ export const sitesCommand = (args: string[]) => {
return sitesRmSubcommand(args.slice(1));
}
+ if (args[0] === SITES_RMALL_COMMAND) {
+ return sitesRmallSubcommand();
+ }
+
if (args[0] === SITES_CREATE_SUBCOMMAND) {
return sitesCreateSubcommand(args.slice(1));
}
diff --git a/packages/lambda/src/cli/commands/sites/rmall.ts b/packages/lambda/src/cli/commands/sites/rmall.ts
new file mode 100644
index 0000000000..bcc4383e5a
--- /dev/null
+++ b/packages/lambda/src/cli/commands/sites/rmall.ts
@@ -0,0 +1,59 @@
+import {CliInternals} from '@remotion/cli';
+import {getSites} from '../../..';
+import {deleteSite} from '../../../api/delete-site';
+import {getRemotionS3Buckets} from '../../../api/get-buckets';
+import {getAwsRegion} from '../../get-aws-region';
+import {confirmCli} from '../../helpers/confirm';
+import {formatBytes} from '../../helpers/format-bytes';
+import {quit} from '../../helpers/quit';
+import {Log} from '../../log';
+
+export const SITES_RMALL_COMMAND = 'rmall';
+
+export const sitesRmallSubcommand = async () => {
+ const region = getAwsRegion();
+ const deployedSites = await getSites({
+ region,
+ });
+
+ const {remotionBuckets} = await getRemotionS3Buckets(region);
+
+ if (remotionBuckets.length > 1) {
+ Log.error('You have more than one Remotion Lambda bucket:');
+ for (const bucket of remotionBuckets) {
+ Log.error(`- ${bucket.name}`);
+ }
+
+ Log.error(
+ 'You should only have one - delete all but one before continuing.'
+ );
+ quit(1);
+ }
+
+ if (remotionBuckets.length === 0) {
+ Log.error(
+ `You don't have a Remotion Lambda bucket in the ${region} region. Therefore nothing was deleted.`
+ );
+ quit(1);
+ }
+
+ for (const site of deployedSites.sites) {
+ await confirmCli({
+ delMessage: `Site ${site.id} in bucket ${site.bucketName} (${formatBytes(
+ site.sizeInBytes
+ )}): Delete? (Y/n)`,
+ allowForceFlag: true,
+ });
+
+ const {totalSizeInBytes: totalSize} = await deleteSite({
+ bucketName: remotionBuckets[0].name,
+ siteName: site.id,
+ region,
+ onAfterItemDeleted: ({itemName}) => {
+ Log.info(CliInternals.chalk.gray(`Deleted ${itemName}`));
+ },
+ });
+
+ Log.info(`Deleted site ${site.id} and freed up ${formatBytes(totalSize)}.`);
+ }
+};