-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathdestroy.ts
72 lines (62 loc) · 1.5 KB
/
destroy.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
// Extremely destructive script. Deletes all buckets in your account.
import {getAwsClient, getOrCreateBucket, getRegions} from '@remotion/lambda';
import dotenv from 'dotenv';
import chunk from 'lodash.chunk';
import {getAccountCount} from './src/get-account-count';
import {setEnvForKey} from './src/set-env-for-key';
dotenv.config();
const count = getAccountCount();
console.log(`Found ${count} accounts. Deploying...`);
const execute = async () => {
for (let i = 1; i <= count; i++) {
for (const region of getRegions()) {
setEnvForKey(i);
const {client, sdk} = getAwsClient({
region,
service: 's3',
customCredentials: null,
});
const bucket = await getOrCreateBucket({region});
const files = await client.send(
new sdk.ListObjectsCommand({
Bucket: bucket.bucketName,
})
);
const chunks = chunk(files.Contents ?? [], 10);
for (const file of chunks) {
await Promise.all(
file.map((f) =>
client.send(
new sdk.DeleteObjectCommand({
Bucket: bucket.bucketName,
Key: f.Key,
})
)
)
);
console.log(
'deleted',
file.map((f) => f.Key),
'from bucket',
bucket.bucketName,
'in region',
region,
'in account',
i
);
}
console.log(files.Contents?.length);
await client.send(
new sdk.DeleteBucketCommand({
Bucket: bucket.bucketName,
})
);
}
}
};
execute()
.then(() => process.exit(0))
.catch((err) => {
console.error(err);
process.exit(1);
});