【问题标题】:Accessing my S3 bucket in Amazon访问我在 Amazon 中的 S3 存储桶
【发布时间】:2014-12-03 14:00:40
【问题描述】:
AWS.config.loadFromPath('./AwsConfig.json'); 

var params = {
        Bucket: 'test-dev-2',
        Key: file,
        Body: data
    };


    s3.putObject(params, function(err) {
        if(err) {
            console.log(err);
        }
        else {
            console.log("Success");
        }

我已经在我的 AwsConfig.json 文件中设置了凭据,并且控制台返回了此错误:

{ [TimeoutError: Missing credentials in config]
  message: 'Missing credentials in config',
  code: 'CredentialsError',
  time: Wed Oct 08 2014 16:05:18 GMT-0300 (BRT),
  originalError: 
   { message: 'Could not load credentials from any providers',
     code: 'CredentialsError',
     time: Wed Oct 08 2014 16:05:18 GMT-0300 (BRT),
     originalError: 
      { message: 'Connection timed out after 1000ms',
        code: 'TimeoutError',
        time: Wed Oct 08 2014 16:05:18 GMT-0300 (BRT) } } }

凭据没有错。。有人知道为什么会出错吗?

【问题讨论】:

  • 遇到同样的问题,但时断时续。你解决了吗?

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


【解决方案1】:

您的 json 文件应该看起来像这样(我在其中添加了一些“asdf”:)

{ "accessKeyId": "ACIAIasdfasdfBEF", "secretAccessKey": "1+eOuyasdfasdasdfEn1", "region": "us-west-2", "apiVersions": { "s3": "2006-03-01", "ses": "2010-12-01" } }

另外,在您的 AWS 控制台中,确保用户密钥可以访问 S3。创建一个新用户组,向该组添加“S3 Full”权限,并创建一个属于该安全组(不是您的管理员组!)的新用户!

还有一个。我没有看到您是如何创建 s3 变量的。我像这样创建我的服务器启动:

AWS.config.loadFromPath( './aws-config.json' );
AWS.s3 = new AWS.S3();

然后在代码中我访问它类似于你:AWS.s3.putObject(...)

【讨论】:

  • 嘿@clay,我做了一切,我创建了一个新组和一个新用户,并将这个用户分配给这个组..但仍然有同样的问题......
  • 嘿@Nescau,我不确定问题可能是什么。等你弄明白后发回这里!
【解决方案2】:

在尝试了所有选项后,这对我有用

AWS.config = new AWS.Config();
AWS.config.accessKeyId = "accessKey";
AWS.config.secretAccessKey = "SecretAccessKey";

但硬编码安全密钥并不是一个好习惯。因此,将尽快使用 aws 推荐的安全选项更新这篇文章

【讨论】:

    【解决方案3】:

    在获取 s3 对象之前实例化配置很重要。

    AWS.config.loadFromPath('./awsCredentials.json');
    var s3 = new AWS.S3();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-12
      • 2016-01-22
      • 2017-02-12
      相关资源
      最近更新 更多