Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does S3.deleteObject not fail when the specified key doesn't exist?

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)
})
like image 276
aknuds1 Avatar asked Jun 07 '15 19:06

aknuds1


People also ask

What happens if you Delete a Delete marker in S3?

A delete marker in Amazon S3 is a placeholder (or marker) for a versioned object that was named in a simple DELETE request. Because the object is in a versioning-enabled bucket, the object is not deleted. But the delete marker makes Amazon S3 behave as if it is deleted.

What does the specified key does not exist mean?

model. AmazonS3Exception: The specified key does not exist. This error usually occurs when a file is removed when a query is running. Either rerun the query, or check your workflow to see if another job or process is modifying the files when the query is running.

Does not exist or you do not have permissions to access it the specified key does not exist service Amazon S3 status code 404 error code Nosuchkey?

Amazon S3 generally returns 404 errors if the requested object is missing from the bucket. Before users make GET or HEAD requests for an object, make sure that the object is created and available in the S3 bucket.


1 Answers

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.

like image 165
adeneo Avatar answered Oct 10 '22 02:10

adeneo