Skip to content

Commit

Permalink
fix(store): verify that the s3Client has a region before attempting t…
Browse files Browse the repository at this point in the history
…o resolve the bucket
  • Loading branch information
dirkdev98 committed Jun 7, 2023
1 parent 55df944 commit 4d25a94
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/store/src/object-storage.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ export function objectStorageCreateClient(
* @param {import("@aws-sdk/client-s3").S3Client} s3Client
* @param {{
* bucketName: string,
* locationConstraint: import("@aws-sdk/client-s3").BucketLocationConstraint,
* locationConstraint?: import("@aws-sdk/client-s3").BucketLocationConstraint
* }} options
* @returns {Promise<void>}
*/
export function objectStorageEnsureBucket(
s3Client: import("@aws-sdk/client-s3").S3Client,
options: {
bucketName: string;
locationConstraint: import("@aws-sdk/client-s3").BucketLocationConstraint;
locationConstraint?: import("@aws-sdk/client-s3").BucketLocationConstraint;
},
): Promise<void>;
/**
Expand Down
13 changes: 12 additions & 1 deletion packages/store/src/object-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function objectStorageCreateClient(config) {
* @param {import("@aws-sdk/client-s3").S3Client} s3Client
* @param {{
* bucketName: string,
* locationConstraint: import("@aws-sdk/client-s3").BucketLocationConstraint,
* locationConstraint?: import("@aws-sdk/client-s3").BucketLocationConstraint
* }} options
* @returns {Promise<void>}
*/
Expand All @@ -56,6 +56,17 @@ export async function objectStorageEnsureBucket(s3Client, options) {
});
}

if (
isNil(s3Client.config.region) ||
(typeof s3Client.config.region === "function" &&
isNil(await s3Client.config.region()))
) {
throw AppError.serverError({
message:
"The S3 client is created without a region, make sure to set a region in your environment, the config object or config/credentials files.",
});
}

try {
const headBucketResult = await s3Client.send(
new HeadBucketCommand({ Bucket: options.bucketName }),
Expand Down

0 comments on commit 4d25a94

Please sign in to comment.