How to list AWS S3 buckets using amazon-javascript-sdk?

空扰寡人 提交于 2019-12-11 12:29:04

问题


I need to get a list of buckets having the client accessKeyId and secretAccessKey. From the docs I understood that I have to update de configurations of AWS, create a new S3 object, then call on it the listBuckets() function with the callback.

So, here's my code:

AWS.config.update({
        accessKeyId: awsKey.identifier, secretAccessKey: awsKey.secret, region: awsKey.region,
        apiVersion: '2006-03-01'
    });

let s3 = new AWS.S3();
s3.listBuckets((response, data) => {
    console.log(response);
    console.log(data);
});

The problem is that I get:

Thanks for your attention


回答1:


On the AWS Forums I got an answer that says it's impossible to do that, using amazon-javascript-sdk in the browser.

Here is the post: https://forums.aws.amazon.com/thread.jspa?threadID=179355&tstart=0




回答2:


You need to set permissions of file to public or any authorized user using any user define key while uploading files to amazon bucket. While Uploading files, there is option to set permissions. Thanks, Saurabh.




回答3:


You probably need to configure CORS for your buckets. See AWS docs here: Configuring CORS for an Amazon S3 Bucket



来源:https://stackoverflow.com/questions/29901725/how-to-list-aws-s3-buckets-using-amazon-javascript-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!