How to delete AWS S3 versioning objects
Estimated time to read: 3 minutes
You have learned how to create objects using AWS S3 versioning. In this tutorial, you will learn how to (hard and soft) delete versioning objects in the Fuga S3 Object Store.
Prerequisites
- The steps from from previous tutorial create AWS S3 versioning objects.
Soft delete
With the command delete-object, it is possible to delete a file from a bucket, although it will stay in the versioning
$ aws --profile=ams2 --endpoint=https://core.fuga.cloud:8080 s3api delete-object --bucket versioned --key test.txt
Check the container with list-objects-v2 command what files are still there:
$ aws --profile=ams2 --endpoint=https://core.fuga.cloud:8080 s3api list-objects-v2 --bucket versioned
Check the container with the list-object-versions command:
$ aws --profile=ams2 --endpoint=https://core.fuga.cloud:8080 s3api list-object-versions --bucket versioned
{
"Versions": [
{
"ETag": "\"566c3a260314fea8318ec46ed7efd4c5\"",
"Size": 5,
"StorageClass": "STANDARD",
"Key": "test.txt",
"VersionId": "iGhlB8vxX6vhehgrdyhgo4rkBY74jvo",
"IsLatest": false,
"LastModified": "2021-11-30T09:19:42.967Z",
"Owner": {
"DisplayName": "owner name",
"ID": "owner ID"
}
},
{
"ETag": "\"f4aa19fc7ee46cce02bf1fb6fad054cf\"",
"Size": 5,
"StorageClass": "STANDARD",
"Key": "test.txt",
"VersionId": "EGlSkj1dR.OrtmmmZ0R4DsI5aVPHNcO",
"IsLatest": false,
"LastModified": "2021-11-30T09:19:02.669Z",
"Owner": {
"DisplayName": "owner name",
"ID": "owner ID"
}
},
{
"ETag": "\"dbb126075a1d0b4ca64c3e2ae0159bc7\"",
"Size": 4,
"StorageClass": "STANDARD",
"Key": "test.txt",
"VersionId": "swwQLkp35P87WzjHQmoYkO1KDukcvq2",
"IsLatest": false,
"LastModified": "2021-11-30T09:18:48.423Z",
"Owner": {
"DisplayName": "owner name",
"ID": "owner ID"
}
}
],
"DeleteMarkers": [
{
"Owner": {
"DisplayName": "owner name",
"ID": "owner ID"
},
"Key": "test.txt",
"VersionId": "UA9JuuW67Z6rXl2PHKkBumg6P7I1KQA",
"IsLatest": true,
"LastModified": "2021-11-30T10:30:51.109Z"
}
]
}
You can see there are three versions of the object "test.txt" left in the Object Store. Those objects are still accessible with the get-object command.
Hard Delete
In the above paragraph, you have discovered that deleting an object in a versioned Fuga S3 bucket will not delete the object in reality. To delete the object entirely from the bucket, you have to specify the "VersionId" when deleting the object.
With the same command delete-object and the key VersionId added, it is possible to delete the object entirely. In line with the previous tutorials about versioning, you will now delete the object with the text "animals" in it. This file was the last created one, so find the VersionId of the newest LastModified object.
$ aws --profile=ams2 --endpoint=https://core.fuga.cloud:8080 s3api delete-object --bucket versioned --key test.txt --version-id <newest LastModified>
$ aws --profile=ams2 --endpoint=https://core.fuga.cloud:8080 s3api list-object-versions --bucket versioned
{
"Versions": [
{
"ETag": "\"f4aa19fc7ee46cce02bf1fb6fad054cf\"",
"Size": 5,
"StorageClass": "STANDARD",
"Key": "test.txt",
"VersionId": "EGlSkj1dR.OrtmmmZ0R4DsI5aVPHNcO",
"IsLatest": false,
"LastModified": "2021-11-30T09:19:02.669Z",
"Owner": {
"DisplayName": "owner name",
"ID": "owner ID"
}
},
{
"ETag": "\"dbb126075a1d0b4ca64c3e2ae0159bc7\"",
"Size": 4,
"StorageClass": "STANDARD",
"Key": "test.txt",
"VersionId": "swwQLkp35P87WzjHQmoYkO1KDukcvq2",
"IsLatest": false,
"LastModified": "2021-11-30T09:18:48.423Z",
"Owner": {
"DisplayName": "owner name",
"ID": "owner ID"
}
}
],
"DeleteMarkers": [
{
"Owner": {
"DisplayName": "owner name",
"ID": "owner ID"
},
"Key": "test.txt",
"VersionId": "UA9JuuW67Z6rXl2PHKkBumg6P7I1KQA",
"IsLatest": true,
"LastModified": "2021-11-30T10:30:51.109Z"
}
]
}
Conclusion
In this tutorial, you have learned the differences between a soft and a hard delete, within a Fuga S3 bucket. Also, you learned about the delete-Markers. If you want to know how you can undo those delete markers, check the next step in the versioning series: How to recover a deleted AWS3 versioning object.