I find ActiveRecord::Base.transaction
very effective in complex methods.
I was wondering if its possible to upload/remove files from AWS S3 within a transaction like:
S3Object.transaction do
# write into files
# raise an exception
end
After the exception is raised every action should be rolled back on S3. Is this possible with S3Object?
Navigate to the Amazon S3 bucket or folder that contains the objects that you want to delete. Select the check box to the left of the names of the objects that you want to delete. Choose Actions and choose Delete from the list of options that appears. Alternatively, choose Delete from the options in the upper right.
If you no longer need to store the file you've uploaded to your Amazon S3 bucket, you can delete it. Within your S3 bucket, select the file that you want to delete, choose Actions, and then choose Delete. In the confirmation message, choose OK.
When you upload large files to Amazon S3, it's a best practice to leverage multipart uploads. If you're using the AWS Command Line Interface (AWS CLI), then all high-level aws s3 commands automatically perform a multipart upload when the object is large. These high-level commands include aws s3 cp and aws s3 sync.
To prevent or mitigate future accidental deletions, consider the following features: Enable versioning to keep historical versions of an object. Enable Cross-Region Replication of objects. Enable MFA delete to require multi-factor authentication (MFA) when deleting an object version.
Although the S3 API has a bulk delete functionality, it does not support transactions as each delete operation can succeed/fail independently of the others.
The API does not provide any bulk upload functionality (through PUT or POST) so each upload operation is done through an independent API call that can succeed or fail.
As a result, the Ruby API client or any other API clients can not provide any transactional support for S3 operations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With