Skip to content

Instantly share code, notes, and snippets.

@rafaelrinaldi
Created July 7, 2017 02:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafaelrinaldi/1709be97c13c4a44ed7cd99874f118cb to your computer and use it in GitHub Desktop.
Save rafaelrinaldi/1709be97c13c4a44ed7cd99874f118cb to your computer and use it in GitHub Desktop.
Upload a JSON file to an S3 bucket
(ns facebook-campaigns-resolver.core
(:require [cheshire.core :as json]
[clj-http.client :as http]
[amazonica.aws.s3 :as s3]
[amazonica.aws.s3transfer :as s3transfer]
[clojure.java.io :as io]))
(def ^:private url "https://jsonplaceholder.typicode.com/comments?postId=1")
(def ^:private aws {:key ""
:secret ""
:bucket ""
:region "us-west-1"})
(defn get-json [url]
(:body (http/get url)))
(defn save-to-s3
[json]
(let [payload (.getBytes json "UTF-8")
input-stream (java.io.ByteArrayInputStream. payload)]
(s3/put-object :bucket-name (:bucket aws)
:access-key (:key aws)
:secret-key (:secret aws)
:file json)))
(save-to-s3 (get-json url))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment