大家好我试图使用节点js从我的s3存储桶中删除对象这里是我的服务器端脚本将执行
var aws = require('aws-sdk');
var s33 = new aws.S3();
aws.config.update({
accessKeyId: "xxxxxxxxxxxxxxxxxxxxxx",
secretAccessKey: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
bucket : "xxxxxxxxxxxx",
region: "us-east-1"
});
app.post('/deleteObj',function(req, res) {
var params = {
Bucket: 'xxxxxxxxxxxxx',
Delete: { // required
Objects: [ // required
{
Key: 'some-key' // required
},
/*{
Key: 'sample-image--10.jpg'
}*/
],
},
};
s33.deleteObjects(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
});
显示错误凭据错误,不应该发生,因为我只能使用这些凭据进行基于浏览器的POST上传。
这是错误日志:
CredentialsError: Missing credentials in config
at IncomingMessage.<anonymous> (/home/ubuntu/xxxxxx/node_modules/aws-sdk/lib/util.js:864:34)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickDomainCallback (internal/process/next_tick.js:128:9)
message: 'Missing credentials in config',
retryable: false,
time: 2017-11-17T06:43:51.657Z,
code: 'CredentialsError',
originalError:
{ message: 'Could not load credentials from any providers',
retryable: false,
time: 2017-11-17T06:43:51.657Z,
这里是桶的cors配置,如果它有帮助,请看看这个:
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>http://xxxxxxxxxxxxxxxxxxxxxxxxxxxx</AllowedOrigin>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>GET</AllowedMethod>
<AllowedHeader>Authorization</AllowedHeader>
</CORSRule>
</CORSConfiguration>
让我知道你对此的看法。
-Thanks
答案 0 :(得分:2)
当您使用AWS API时,不涉及CORS。
您的问题是您在创建S3客户端后分配凭据。
将您的代码更改为:
var aws = require('aws-sdk');
aws.config.update({
accessKeyId: "xxxxxxxxxxxxxxxxxxxxxx",
secretAccessKey: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
bucket : "xxxxxxxxxxxx",
region: "us-east-1"
});
var s33 = new aws.S3();