Interview Prep/Real-World Interview/Data loss and corruption

A cleanup script deleted every object under `s3://acme-invoices/2025/`. Versioning is enabled.

BeginnerTroubleshootingData loss and corruption
Answer

Likely causes → With versioning on, a plain delete doesn't remove data; it adds a delete marker on top of each object. The previous versions are still there.

Diagnose →

aws s3api list-object-versions --bucket acme-invoices --prefix 2025/ \
  --query 'DeleteMarkers[?IsLatest==`true`].[Key,VersionId]' --output text | head

Fix → Remove the delete markers so the previous versions become current again:

aws s3api list-object-versions --bucket acme-invoices --prefix 2025/ \
  --query 'DeleteMarkers[?IsLatest==`true`].[Key,VersionId]' --output text |
while read -r key ver; do
  aws s3api delete-object --bucket acme-invoices --key "$key" --version-id "$ver"
done

For millions of objects, use S3 Batch Operations with an inventory report.

Prevent → Keep versioning on with a lifecycle rule for noncurrent versions (for example 30 days), enable MFA delete or Object Lock for critical buckets, and scope cleanup scripts' IAM to the prefixes they really own.

All Real-World Interview questions Roadmap: Interview readiness

More on Data loss and corruption