An opinionated Clojure Library for AWS S3
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
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.
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.