GithubHelp home page GithubHelp logo

better_s3's Introduction

better_s3

An idiomatic pattern for working with s3 in Ruby

CircleCI

Get the contents of a remote file

require "better_s3"
s3 = BetterS3.new
s3.get "some-filename.txt"
 => "filescontentshere"

Delete local copy of remote file

When downloading files from s3 there are benefits associated with storing a copy locally (most notably it enables retry during download). As such BetterS3 stores a copy of files you get locally. If you want to delete one ...

require "better_s3"
s3 = BetterS3.new
s3.delete_local_file_copy "some-filename.txt"

Put an arbitrary String to a remote file

require "better_s3"
s3 = BetterS3.new
content = { foo: "bar" }.to_json
s3.put "filename.ext", content

Override the client's bucket name

If you need to change buckets, you don't have to create a new client or modify the configuration.

require "better_s3"
BetterS3.configure do |c|
    c.bucket = "bucketname"
end
s3 = BetterS3.new
s3.bucket
 => "bucketname"
s3.bucket = "otherbucket"
s3.bucket
 => "otherbucket"
BetterS3.configuration.bucket
 => "bucketname"

Configuration

To configure BetterS3 use the configuration block pattern

require "better_s3"
BetterS3.configure do |config|
    # The name of the S3 bucket you plan to interact with
    config.bucket = "your-bucket-name"
    
    # The local path you want to use for temporary file
    # storage
    config.tmp_dir_path = "../tmp"
    
    # If you want to hardcode which region of SQS should be used then you can set this option. It is recommended
    # to use the environment variable ENV["AWS_REGION"] instead
    config.region = "us-west-2"
    
    # for aws_access_key_id and aws_secret_access_key you can set them in this fashion, but it is strongly
    # recommended that you just use the environment variables instead: ENV["AWS_ACCESS_KEY_ID"], 
    # ENV["AWS_SECRET_ACCESS_KEY"]
end

better_s3's People

Contributors

caldwecr avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.