Why does S3.deleteObject fail if the specified key does not exist?

Using the AWS SDK for Node , why am I not getting an error when I try to delete an object that does not exist (i.e. the S3 key is incorrect)?

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

If you are considering the following Node program, the Key parameter lists a key that does not exist in the bucket, but the error argument for 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) }) 
+6
source share
1 answer

Because what specs says needs to be done.

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

Deletes the zero version (if any) of the object and inserts a delete marker, which becomes the latest version of the object. If there is no version zero, Amazon S3 does not delete any objects.

So, if the object does not exist, it is still not an error when deleteObject called, it still adds a delete token.

+9
source

Source: https://habr.com/ru/post/988669/


All Articles