@@ -5,14 +5,28 @@ const { prop, map } = R
55
66export const createPrefix = ( prefix ) => ( str ) => `${ prefix } -${ str } `
77
8- export const Multi = ( bucketPrefix ) => {
8+ export const Multi = ( { bucketPrefix, region } ) => {
99 if ( ! bucketPrefix ) throw new Error ( 'bucketPrefix is required' )
1010
1111 const bucketWithPrefix = createPrefix ( bucketPrefix )
1212
1313 const makeBucket = ( minio ) => {
1414 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 ) => {
1630 if ( isBucketExistsErr ( err ) ) throw HyperErr ( { status : 409 , msg : 'bucket already exists' } )
1731 throw err // some other err
1832 } )
0 commit comments