GithubHelp home page GithubHelp logo

s3c's Introduction

An opinionated Clojure Library for AWS S3

Usage

Add below to deps.edn

omnyway-labs/s3c
{:git/url "https://github.com/omnyway-labs/s3c.git"
 :sha "d7c3042931f4b0fda2c6c9247e6bceae7fa30b95"}
(require '[s3c.core :as s3])
(s3/init! {:provider :profile
           :profile (System/getenv "AWS_PROFILE")})

(s3/put bucket key stream metadata)

;; example
(s3/put bucket "foo.png"
        (io/input-stream (.getBytes "text"))
        {:content-type "image/png"})

;=> https//bucket.s3.amazonaws.com/foo.png

;; put also takes an ACL idenitifer or map

(s3/put bucket key stream metadata acl)

(s3/put bucket key stream metadata :public)
;; makes it world readable

(s3/get bucket key)

;; for string puts and gets
(s3/put-str bucket "foo.txt" "some-string")
(s3/get-str bucket "foo.txt")
;=> "some-string"

(s3/delete bucket key)

(s3/parse-path "s3://bucket/key")
;=> {:bucket bucket :key key}

(s3/list-keys bucket prefix)

(s3/list-common-prefixes bucket)
;=> returns list of top-level root prefixes

AWS s3-select Wrappers

s3c makes it easy to use EDN maps as filters in select param

Below is an idiomatic way to use s3-select

(s3/select s3-bucket prefix filters)

;;returns a lazy-seq of the S3 logs.

;; we can optionally write the results to a file
(s3/select "my-bucket" prefix filters "/tmp/data.json")

Say we have some data in a S3 bucket like below:

{"id":1,"name":"foo.bar","address":"Las Vegas","car":"golf", "context": {"request-id": "Root-1=abc"}}
{"id":2,"name":"Ben Mostafa","address":"Las Vegas","car":"Mustang"}
(s3/select "my-bucket" "2018/12/10" {:id 1})

;; or for nested data use a dotted notation
(s3/select "my-bucket" "2018/12/10" {:context.request-id "Root-1=abc"})

s3c supports select on only GZIPPed JSON encoded logs, currently.

License - Apache 2.0

Copyright 2019 Omnyway Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

s3c's People

Contributors

icylisper avatar

Watchers

Angus Fletcher avatar James Cloos 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.