简体   繁体   中英

Clearing an s3 bucket with aws-sdk

I've been working with the aws/s3 gem up until this point and had to switch to aws-sdk gem for this project. In the aws/s3 gem, you could get a reference to a bucket and then call:

bucket.clear

To delete everything in the bucket. How can I do this with the aws-sdk gem?

现在,aws-sdk gem支持此功能。

bucket#clear!

You can augment the AWS::S3::Bucket class by putting a twist on the delete! method. Since classes are always open in Ruby this is pretty trivial.

module AWS
  class S3
    class Bucket
      def clear_objects!
        versions.each_batch { |batch| objects.delete(batch) }
      end
    end
  end
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM