Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use transactional file remove/upload on AWS S3 with aws-sdk-ruby?

Tags:

ruby

amazon-s3

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?

like image 571
p1100i Avatar asked Jul 31 '13 10:07

p1100i


People also ask

What is the best way to delete multiple objects from S3?

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.

How do I delete files from Amazon S3?

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.

What is the best way for the application to upload the large files in S3?

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.

What is the best way to protect a file in Amazon S3 against accidental delete?

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.


1 Answers

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.

like image 178
dcro Avatar answered Nov 04 '22 14:11

dcro