admin管理员组文章数量:1410682
i get an object storage service from a pany and they use aws s3 structure.so you can use libraries designed for aws s3 to connect to there storage(libraries like boto3 for python and aws-sdk for javascript).i use aws-sdk.
i need to use an ip address to access the storage so i need to set endpoint to their ip address, and it works fine. problem is that this pany file storage system is a bit different than aws. while aws use bucket name as a subdomain, this pany use bucket name in the path of the file.
aws: bucket.amazon
their: <-ipaddress->/public/bucket/...
and its just fine when using boto3, but when i use aws-sdk and when i set bucket in params, aws-sdk set bucket as subdomin of ip address and it dont work any more.
since it work fine when using boto3, i thought it must work with aws-sdk as well. so im looking for a way to prevent aws-sdk to set bucket as subdomain and use it in a different way.
const AWS = require("aws-sdk");
const ep = new AWS.Endpoint("http://<ip address>");
global.s3 = new AWS.S3({
apiVersion: "2006-03-01",
endpoint: ep,
});
const params = {
Bucket: `${process.env.AWS_BUCKET}`,
Prefix: `${_path}`,
};
const result = await s3.listObjects(params).promise();
result of the above code is this error:
Inaccessible host: <bucket>.<ip address>. This service may not be available in the us-east-1' region.'
whick is currect because this address does not exists. but how can i fix this.
it works fine when im getting bucket list and bucket is not set.
i get an object storage service from a pany and they use aws s3 structure.so you can use libraries designed for aws s3 to connect to there storage(libraries like boto3 for python and aws-sdk for javascript).i use aws-sdk.
i need to use an ip address to access the storage so i need to set endpoint to their ip address, and it works fine. problem is that this pany file storage system is a bit different than aws. while aws use bucket name as a subdomain, this pany use bucket name in the path of the file.
aws: bucket.amazon.
their: <-ipaddress->/public/bucket/...
and its just fine when using boto3, but when i use aws-sdk and when i set bucket in params, aws-sdk set bucket as subdomin of ip address and it dont work any more.
since it work fine when using boto3, i thought it must work with aws-sdk as well. so im looking for a way to prevent aws-sdk to set bucket as subdomain and use it in a different way.
const AWS = require("aws-sdk");
const ep = new AWS.Endpoint("http://<ip address>");
global.s3 = new AWS.S3({
apiVersion: "2006-03-01",
endpoint: ep,
});
const params = {
Bucket: `${process.env.AWS_BUCKET}`,
Prefix: `${_path}`,
};
const result = await s3.listObjects(params).promise();
result of the above code is this error:
Inaccessible host: <bucket>.<ip address>. This service may not be available in the us-east-1' region.'
whick is currect because this address does not exists. but how can i fix this.
it works fine when im getting bucket list and bucket is not set.
Share Improve this question edited Nov 23, 2020 at 13:57 halo asked Nov 23, 2020 at 13:51 halohalo 10110 bronze badges2 Answers
Reset to default 8after three days looking for the answer, finally find the solution. aws s3 has two way of handling bucket.
: use it in subdomain to connect to it
: use it in the path of your object
in my case i should use the second way and the way to do it is to config aws-sdk and set s3ForcePathStyle
to true. like this: AWS.config.s3ForcePathStyle = true;
and problem solved.
Based on the answer of @halo, I was able to figure out how to do this with the S3 Client to e.g connect to a s3 patible storage like OBS (open telekom cloud, Huawai cloud etc.) or to connect to e.g minio running locally.
import { S3Client } from '@aws-sdk/client-s3';
new S3Client({
forcePathStyle: true, // needed for localstack
endpoint: 'localhost:9000', //when using minio
credentials: {
secretAccessKey: 'hello',
accessKeyId: 'supersecret',
},
}),
本文标签:
版权声明:本文标题:javascript - how to prevent aws-sdk from setting bucket as subdomain for an ip address as endpoint - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744969099a2635125.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论