在Amazon中访问我的S3存储桶
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"); }
我alredy在我的AwsConfig.json文件中设置了credencials,并且它的控制台返回了这个错误:
{ [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文件应该看起来像这样(我在那里添加了一些“asdf”):
{ "accessKeyId": "ACIAIasdfasdfBEF", "secretAccessKey": "1+eOuyasdfasdasdfEn1", "region": "us-west-2", "apiVersions": { "s3": "2006-03-01", "ses": "2010-12-01" } }
另外,在您的AWS控制台中,确保用户密钥可以访问S3。 创build一个新的用户组,为该组添加“S3 Full”权限,并创build一个属于该安全组的新用户( 不是您的pipe理员组)!
多一个。 我没有看到你如何创builds3
variables。 我创build像这样的服务器启动:
AWS.config.loadFromPath( './aws-config.json' ); AWS.s3 = new AWS.S3();
然后在代码中,我访问它类似于你: AWS.s3.putObject(...)
尝试所有选项后,这对我工作
AWS.config = new AWS.Config(); AWS.config.accessKeyId = "accessKey"; AWS.config.secretAccessKey = "SecretAccessKey";
但是对硬编码安全密钥不是一个好的做法。 所以将尽快更新这个职位与安全选项由aws推荐
在获取s3对象之前实例化configuration很重要。
AWS.config.loadFromPath('./awsCredentials.json'); var s3 = new AWS.S3();