You also need to understand how enabling versioning on a bucket would help. There are use cases where a file is updated regularly, and versions will be created for the same file. To simulate this scenario, try the following example:
$ echo “Version-1″>version-doc.txt
$ aws s3 cp version-doc.txt s3://version-demo-mlpractice
$ aws s3 cp s3://version-demo-mlpractice/version-doc.txt
check.txt
$ cat check.txt
Version-1
$ echo “Version-2″>version-doc.txt
$ aws s3 cp version-doc.txt s3://version-demo-mlpractice
$ aws s3 cp s3://version-demo-mlpractice/version-doc.txt
check.txt
$ cat check.txt
Version-2
$ aws s3api list-object-versions
–bucket version-demo-mlpractice
{
“Versions”: [
{
“ETag”:
“\”b6690f56ca22c410a2782512d24cdc97\””,
“Size”: 10,
“StorageClass”: “STANDARD”,
“Key”: “version-doc.txt”,
“VersionId”:
“70wbLG6BMBEQhCXmwsriDgQoXafFmgGi”,
“IsLatest”: true,
“LastModified”: “2020-11-07T15:57:05+00:00”,
“Owner”: {
“DisplayName”: “baba”,
“ID”: “XXXXXXXXXXXX”
}
},
{
“ETag”: “\”5022e6af0dd3d2ea70920438271b21a2\””,
“Size”: 10,
“StorageClass”: “STANDARD”,
“Key”: “version-doc.txt”,
“VersionId”: “f1iC.9L.MsP00tIb.sUMnfOEae240sIW”,
“IsLatest”: false,
“LastModified”: “2020-11-07T15:56:27+00:00”,
“Owner”: {
“DisplayName”: “baba”,
“ID”: ” XXXXXXXXXXXX”
}
}
]
}
$ aws s3api delete-object –bucket version-demo-mlpractice –key version-doc.txt
{
“DeleteMarker”: true,
“VersionId”: “BKv_Cxixtm7V48MWqBO_KUkKbcOaH5JP”
}
aws s3api list-object-versions –bucket version-demo-mlpractice
$ aws s3 ls s3://version-demo-mlpractice/
$ aws s3api delete-object –bucket version-demo-mlpractice –key version-doc.txt –version-id BKv_Cxixtm7V48MWqBO_KUkKbcOaH5JP
{
“DeleteMarker”: true,
“VersionId”: “BKv_Cxixtm7V48MWqBO_KUkKbcOaH5JP”
}
$ aws s3 ls s3://version-demo-mlpractice/
2020-11-07 15:57:05 10 version-doc.txt
As you have already covered the exam topics and practiced most of the required concepts, you should delete the objects in the bucket and then delete the bucket to save on costs. This step deletes the versions of the object and, in turn, removes the object permanently.
$ aws s3api delete-object –bucket version-demo-mlpractice –key version-doc.txt –version-id 70wbLG6BMBEQhCXmwsriDgQoXafFmgGi
$ aws s3api delete-object –bucket version-demo-mlpractice –key version-doc.txt –version-id f1iC.9L.MsP00tIb.sUMnfOEae240sIW
$ aws s3api list-object-versions –bucket version-demo-mlpractice
You can clearly see the empty bucket now.