@@ -5,14 +5,28 @@ const { prop, map } = R
5
5
6
6
export const createPrefix = ( prefix ) => ( str ) => `${ prefix } -${ str } `
7
7
8
- export const Multi = ( bucketPrefix ) => {
8
+ export const Multi = ( { bucketPrefix, region } ) => {
9
9
if ( ! bucketPrefix ) throw new Error ( 'bucketPrefix is required' )
10
10
11
11
const bucketWithPrefix = createPrefix ( bucketPrefix )
12
12
13
13
const makeBucket = ( minio ) => {
14
14
return asyncifyHandle ( ( name ) =>
15
- minio . makeBucket ( bucketWithPrefix ( name ) ) . catch ( ( err ) => {
15
+ /**
16
+ * When using with AWS s3 and coupled with the fact that LocationConstraint
17
+ * is not required _only_ for us-east-1 (https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateBucketConfiguration.html),
18
+ * this can cause some hair-pulling gotchas when creating a bucket and not passing region -- the bucket will automatically
19
+ * be attempted to be created in us-east-1, REGARDLESS of whichever region used to instantiate the MinIO Client.
20
+ *
21
+ * So if you're using something like IAM to securely access s3, or a VPC Endpoint for s3 in a region that is _not_ us-east-1,
22
+ * you will simply get an opaque S3 AccessDenied error when creating the bucket -- your IAM Role might be constrained to only
23
+ * access, say us-east-2, or your VPC Endpoint is for s3.us-east-2.amazonaws.com, and accessing us-east-1 out of the blue
24
+ * will simply produce a seemingly incoherent "AccessDenied". -_______-
25
+ *
26
+ * SO, we MUST pass region here that is provided to the adapter, to ensure the bucket is created in the desired region,
27
+ * and any credentials imbued by IAM or the VPC are used.
28
+ */
29
+ minio . makeBucket ( bucketWithPrefix ( name ) , region ) . catch ( ( err ) => {
16
30
if ( isBucketExistsErr ( err ) ) throw HyperErr ( { status : 409 , msg : 'bucket already exists' } )
17
31
throw err // some other err
18
32
} )
0 commit comments