head bucket

This commit is contained in:
fyears
2021-11-07 15:43:57 +08:00
parent 2ce34379ad
commit a65f5eb004
2 changed files with 56 additions and 1 deletions
+29
View File
@@ -10,6 +10,7 @@ import {
GetObjectCommand,
DeleteObjectCommand,
HeadObjectCommand,
HeadBucketCommand,
} from "@aws-sdk/client-s3";
import type { _Object } from "@aws-sdk/client-s3";
@@ -266,3 +267,31 @@ export const deleteFromRemote = async (
// pass
}
};
/**
* Check the config of S3 by heading bucket
* https://stackoverflow.com/questions/50842835
* @param s3Client
* @param s3Config
* @returns
*/
export const checkS3Connectivity = async (
s3Client: S3Client,
s3Config: S3Config
) => {
try {
const results = await s3Client.send(
new HeadBucketCommand({ Bucket: s3Config.s3BucketName })
);
if (
results === undefined ||
results.$metadata === undefined ||
results.$metadata.httpStatusCode === undefined
) {
return false;
}
return results.$metadata.httpStatusCode === 200;
} catch (err) {
return false;
}
};