generated from remotion-dev/template-next-app-dir
-
Notifications
You must be signed in to change notification settings - Fork 76
/
delete.ts
78 lines (69 loc) · 1.97 KB
/
delete.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import type { AwsRegion } from "@remotion/lambda";
import { getAwsClient, getOrCreateBucket, getRegions } from "@remotion/lambda";
import dotenv from "dotenv";
import pLimit from "p-limit";
import { getAccountCount } from "./src/helpers/get-account-count";
import { setEnvForKey } from "./src/helpers/set-env-for-key";
dotenv.config();
const count = getAccountCount();
console.log(`Found ${count} accounts. Deploying...`);
const limit = pLimit(10);
const doTheThingForRegion = (i: number, region: AwsRegion) =>
limit(async () => {
setEnvForKey(i);
const { bucketName } = await getOrCreateBucket({ region });
const { sdk, client } = getAwsClient({ region, service: "s3" });
const results = [];
let contToken: string | undefined;
// eslint-disable-next-line no-constant-condition
while (true) {
const res = await client.send(
new sdk.ListObjectsV2Command({
Bucket: bucketName,
Prefix: "renders",
ContinuationToken: contToken,
}),
);
if ((res.Contents?.length ?? 0) > 0) {
await client.send(
new sdk.DeleteObjectsCommand({
Bucket: bucketName,
Delete: {
Objects: res.Contents?.map((c) => ({
Key: c.Key as string,
})),
},
}),
);
results.push(...(res.Contents ?? []));
console.log(
"Deleted",
results.length,
"objects in",
bucketName,
"in",
region,
"for account",
i,
);
} else {
console.log(
"No more objects to delete in",
bucketName,
"in",
region,
"for account",
i,
);
}
if (!res.NextContinuationToken) {
break;
}
contToken = res.NextContinuationToken;
}
});
for (let i = 1; i <= count; i++) {
for (const region of getRegions()) {
doTheThingForRegion(i, region);
}
}