Skip to content

Commit 4d25a94

Browse files
committed
fix(store): verify that the s3Client has a region before attempting to resolve the bucket
1 parent 55df944 commit 4d25a94

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

packages/store/src/object-storage.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ export function objectStorageCreateClient(
2424
* @param {import("@aws-sdk/client-s3").S3Client} s3Client
2525
* @param {{
2626
* bucketName: string,
27-
* locationConstraint: import("@aws-sdk/client-s3").BucketLocationConstraint,
27+
* locationConstraint?: import("@aws-sdk/client-s3").BucketLocationConstraint
2828
* }} options
2929
* @returns {Promise<void>}
3030
*/
3131
export function objectStorageEnsureBucket(
3232
s3Client: import("@aws-sdk/client-s3").S3Client,
3333
options: {
3434
bucketName: string;
35-
locationConstraint: import("@aws-sdk/client-s3").BucketLocationConstraint;
35+
locationConstraint?: import("@aws-sdk/client-s3").BucketLocationConstraint;
3636
},
3737
): Promise<void>;
3838
/**

packages/store/src/object-storage.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function objectStorageCreateClient(config) {
4545
* @param {import("@aws-sdk/client-s3").S3Client} s3Client
4646
* @param {{
4747
* bucketName: string,
48-
* locationConstraint: import("@aws-sdk/client-s3").BucketLocationConstraint,
48+
* locationConstraint?: import("@aws-sdk/client-s3").BucketLocationConstraint
4949
* }} options
5050
* @returns {Promise<void>}
5151
*/
@@ -56,6 +56,17 @@ export async function objectStorageEnsureBucket(s3Client, options) {
5656
});
5757
}
5858

59+
if (
60+
isNil(s3Client.config.region) ||
61+
(typeof s3Client.config.region === "function" &&
62+
isNil(await s3Client.config.region()))
63+
) {
64+
throw AppError.serverError({
65+
message:
66+
"The S3 client is created without a region, make sure to set a region in your environment, the config object or config/credentials files.",
67+
});
68+
}
69+
5970
try {
6071
const headBucketResult = await s3Client.send(
6172
new HeadBucketCommand({ Bucket: options.bucketName }),

0 commit comments

Comments
 (0)