I have application server written in Node.js which upload files to AWS S3 storage. For that I'm using https://www.npmjs.com/package/aws-sdk and when I'm connecting to and uploading to my AWS production storage it is working fine. However during development I want to upload files to local MinIO server (create from docker image https://hub.docker.com/r/minio/minio/):
docker run -p 9000:9000 -p 9001:9001 \
quay.io/minio/minio server /minio --console-address ":9001"
MinIO server itself is working fine, I'm able to login there locally, create buckets, etc. However when I tried to upload file to my local MinIO storage using AWS SDK for node.js I'm unable to do so:
import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3';
#s3Client = new S3Client({
credentials: {
accessKeyId: config.getAwsStorageAccessKeyId(), // from env variables
secretAccessKey: config.getAwsStorageSecretAccessKey(),
},
...(globalConfig.isReleaseVersion() && {
endpoint: config.getAwsStorageEndpoint(), // from env "http://localhost:9001"
}),
});
And later I'm trying to upload object:
await this.#s3Client.send(new PutObjectCommand({
Bucket: config.getAwsStorageWebflowBucketName(), // from env "test" value
Key: 'example.json',
Body: body, // a buffer
}));
I'm receiving error:
ERROR EndpointError: Custom endpoint `test.127.0.0.1://9001/` was not a valid URI
However I'm able to reach address http://test.localhost:9001/ from my browser. When I try to pass directly value 'http://localhost:9001/'
as an endpoint to S3Client
configuration, I'm getting error:
ERROR Error: getaddrinfo ENOTFOUND test.localhost
Looks like port value is ignored my SDK. How can this be fixed?
<Yes, I know there is separate MinIO SDK - I want to use one provided by AWS, existence of endpoint
parameter in configuration implies that it should be possible>
CodePudding user response:
the listener endpoint for S3 API is port 9000, 9001 is for dashboard, also remove region when using Minio, because I think Minio doesn't need it. by so, sdk will not give a prefix 'test' for the endpoint.
CodePudding user response:
Have you tried the option "s3ForcePathStyle" ? I had to use this config to make it work on a local environment
options.s3ForcePathStyle = true
See https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Config.html#s3ForcePathStyle-property
So in your code
...(globalConfig.isReleaseVersion() && {
endpoint: config.getAwsStorageEndpoint(), // from env "http://localhost:9001",
s3ForcePathStyle: true,
}),