I need to configure my s3 bucket in a way that when a user inserts a file into the bucket which already exists in the bucket it should block the user inserting that file.
I thought of implementing an object block with a retention policy on the bucket but the object lock does not block the user to insert the file, it only protects the existing file.
This is what AWS documentation says about the object lock.
If you put an object into a bucket that has the same key name as an
existing protected object, Amazon S3 creates a new version of that
object, stores it in the bucket as requested, and reports the request
as completed successfully.
https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lock.html
How can I block any kind of inserts/overwrites if a file with the same name already exists in the bucket?
2
Answers
The only ways I can think of are:
It’s probably not reasonable because you would have to include every object in the bucket in the policy, and update it as objects are added.
I did not try it myself but
PutObject
via bucket conditional policy usings3:object-lock-mode
ors3:object-lock-remaining-retention-days
conditions