Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
194
rated 0 times [  196] [ 2]  / answers: 1 / hits: 15133  / 9 Years ago, sun, june 7, 2015, 12:00:00

Using the AWS SDK for Node, why do I not get an error when trying to delete an object that doesn't exist (i.e. the S3 key is wrong)?



If I specify a non-existent bucket on the other hand, an error is produced.



If you consider the following Node program, the Key parameter lists a key which doesn't exist in the bucket, yet the error argument to the callback is null:



var aws = require('aws-sdk')

function getSetting(name) {
var value = process.env[name]
if (value == null) {
throw new Error('You must set the environment variable ' + name)
}
return value
}

var s3Client = new aws.S3({
accessKeyId: getSetting('AWSACCESSKEYID'),
secretAccessKey: getSetting('AWSSECRETACCESSKEY'),
region: getSetting('AWSREGION'),
params: {
Bucket: getSetting('S3BUCKET'),
},
})
picturePath = 'nothing/here'
s3Client.deleteObject({
Key: picturePath,
}, function (err, data) {
console.log('Delete object callback:', err)
})

More From » node.js

 Answers
2

Because that's what the specs say it should do.




deleteObject(params = {}, callback) ⇒ AWS.Request



Removes the null version (if there is one) of an object and inserts a
delete marker, which becomes the latest version of the object. If
there isn't a null version, Amazon S3 does not remove any objects.




So if the object doesn't exist, it's still not an error when calling deleteObject, and if versioning is enabled, it adds a delete marker even though there was nothing to delete previously.


[#66294] Thursday, June 4, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
koltenb

Total Points: 276
Total Questions: 92
Total Answers: 101

Location: North Korea
Member since Fri, Nov 4, 2022
2 Years ago
;