July 18, 2024 by Henrique Alves

A safer way to remove old S3 assets

Ever had a close call with accidentally deleting important files? We did, and it taught us a valuable lesson about handling asset expiration.

After a scary incident where we almost lost all our recordings and ID photos due to a sneaky null value, we decided to avoid the risky storage.ls method.

So, how do we manage asset expiration without listing files? The answer is AWS S3 lifecycle policies.

Instead of manually listing and deleting objects, we now use a simple JSON policy.

This policy automatically deletes objects in the specified prefix after a set number of days. We update it daily via a cron job, allowing us to flexibly manage different asset types and expiration periods.

It’s a safer, more efficient way to handle asset expiration. No more nail-biting moments wondering if we’ve accidentally deleted the wrong files!