Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enforce unique file names when uploading to Amazon S3

I have an S3 bucket and have granted access customer to upload file in it. Is there a way to ensure that object names are unique in the S3 bucket without enforcing this requirement on the customer who uploads the file?

I see S3 have versioning capabilities but the object with same name may not be versions of same object but rather totally different object whose names matched unintentionally

like image 557
alwaysAStudent Avatar asked Sep 19 '25 01:09

alwaysAStudent


1 Answers

You can use Amazon S3 Object Lock feature. It can help you prevent objects from being deleted or overwritten for a fixed amount of time or indefinitely.

Note: There are two modes: Governance Mode and Compliance Mode.

In your case you probably should use Governance Mode.

The difference is that in Governance Mode, users can't overwrite or delete an object version or alter its lock settings unless they have special permissions. With Governance Mode, you protect objects against being deleted by most users, but you can still grant some users permission to alter the retention settings or delete the object if necessary.

In Compliance Mode, a protected object version can't be overwritten or deleted by any user, including the root user in your AWS account. When an object is locked in Compliance Mode, its retention mode can't be changed, and its retention period can't be shortened.

like image 175
Dennis Traub Avatar answered Sep 22 '25 21:09

Dennis Traub