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)?
使用AWS SDK for Node,为什么在尝试删除不存在的对象时(即S3键错误),我不会收到错误?
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
:
如果考虑以下Node程序,Key参数列出了存储桶中不存在的密钥,但回调的错误参数为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)
})
1 个解决方案
#1
11
Because that's what the specs say it should do.
因为这是规范所说的应该做的。
deleteObject(params = {}, callback) ⇒ AWS.Request
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.
删除对象的null版本(如果有)并插入删除标记,该标记将成为对象的最新版本。如果没有null版本,则Amazon S3不会删除任何对象。
So if the object doesn't exist, it's still not an error when calling deleteObject
, it still adds the delete marker.
因此,如果该对象不存在,则在调用deleteObject时仍然不是错误,它仍会添加删除标记。
#1
11
Because that's what the specs say it should do.
因为这是规范所说的应该做的。
deleteObject(params = {}, callback) ⇒ AWS.Request
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.
删除对象的null版本(如果有)并插入删除标记,该标记将成为对象的最新版本。如果没有null版本,则Amazon S3不会删除任何对象。
So if the object doesn't exist, it's still not an error when calling deleteObject
, it still adds the delete marker.
因此,如果该对象不存在,则在调用deleteObject时仍然不是错误,它仍会添加删除标记。