mail-s3-admin/s3-list.ts

28 lines
967 B
TypeScript

import dotenv from 'dotenv';
dotenv.config({ path: '.env' });
import { S3Client, ListBucketsCommand } from '@aws-sdk/client-s3';
import http from 'http';
import https from 'https';
// Aktiviere KeepAlive für stabile Connections (verhindert Timeouts bei Wiederholungen)
http.globalAgent.keepAlive = true;
https.globalAgent.keepAlive = true;
(async () => {
try {
console.log('Fetching S3 buckets...');
const s3 = new S3Client({
region: process.env.AWS_REGION,
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
},
httpOptions: { connectTimeout: 30000, timeout: 30000 }, // Erhöhte Timeouts (30s) verhindern ETIMEDOUT
});
const { Buckets } = await s3.send(new ListBucketsCommand({}));
console.log('Buckets:', Buckets?.map(b => b.Name) || 'No buckets found');
} catch (error) {
console.error('Error listing buckets:', error);
}
})();