【问题标题】:AWS s3 api error: specified bucket does not existAWS s3 api 错误:指定的存储桶不存在
【发布时间】:2014-12-16 23:45:11
【问题描述】:

我正在使用节点 AWS SDK 将图像保存到 s3。尽管存储桶存在并且我拥有正确的权限,但我仍然收到以下错误:

{ [NoSuchBucket: The specified bucket does not exist]
  message: 'The specified bucket does not exist',
  code: 'NoSuchBucket',
  time: Tue Oct 21 2014 12:32:50 GMT-0400 (EDT),
  statusCode: 404,
  retryable: false }

我的nodejs代码:

var fs = require('fs');

var AWS = require('aws-sdk'); //AWS library (used to provide temp credectials to a front end user)
AWS.config.loadFromPath('./AWS_credentials.json'); //load aws credentials from the     authentication text file



var s3 = new AWS.S3();

fs.readFile(__dirname + '/image.jpg', function(err, data) {

var params = {
    Bucket: 'https://s3.amazonaws.com/siv.io',
    Key: 'something',
};

s3.putObject(params, function(err, data) {

    if (err) {

        console.log(err);

    } else {
        console.log("Successfully uploaded data to myBucket/myKey");
    }
});
});

我还尝试使用 siv.io.s3-website-us-east-1.amazonaws.com 作为存储桶名称。有人可以让我知道我出了什么问题吗?如有需要,我可以提供更多信息。

【问题讨论】:

    标签: node.js amazon-web-services amazon-s3


    【解决方案1】:

    错误表明存储桶尚不存在。从您的代码来看,存储桶名称不正确,这就是找不到文件的原因。拨打电话createBucket() 或在您的 AWS 控制台中创建存储桶。

    您也可以添加一个文件,而不仅仅是进行 API 调用。检查AWS API docs 以了解将什么放在哪里。他们的文档非常好。

    这是我的工作:

        var stream = fs.createReadStream( 'path/to/file' );
        stream.on( 'error', function( error ) {
          seriesCb( error );
        } );
        //TODO: Other useful options here would be MD5 hash in the `ContentMD5` field,
        s3.putObject( {
          "Bucket": 'siv.io',
          "Key": 'name_of/new_file',
          "ContentType": "application/pdf", //might not apply to you
          "Body": stream
        }, function( s3err, s3results ) {
          if ( s3err ) return console.log('Bad stuff. ' + s3err.toString() );
          console.log( "Saved to S3. uri:" + s3uri);
        } );
    

    【讨论】:

    • 你是对的。我的存储桶命名约定是错误的。命名约定真的很混乱。这个picture 显示了对我有用的方法。
    猜你喜欢
    • 1970-01-01
    • 2020-07-16
    • 1970-01-01
    • 2015-12-07
    • 1970-01-01
    • 1970-01-01
    • 2016-03-02
    • 2023-04-10
    • 2015-10-24
    相关资源
    最近更新 更多