Hi guys I am trying to delete objects from my s3 bucket using node js here is my server side script that will execute
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
});
});
It is showing an error of missing credentials that should not happen as I am able to do a browser-based POST upload using these credentials only.
here is the error log:
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,
here is the cors config of the bucket take a look into this if it helps:
<?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>
Let me know your thoughts on this.
-Thanks