-
Notifications
You must be signed in to change notification settings - Fork 3
/
kinesis_example.cljs
41 lines (36 loc) · 2 KB
/
kinesis_example.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
(ns cljs-aws.kinesis-example
(:require [cljs-aws.kinesis :as kinesis]
[cljs.core.async :refer [go <! timeout]]
[cljs-aws.examples-util :as util :refer [throw-or-print]]))
(enable-console-print!)
(def stream-name "my-stream")
(defn -main
"Example cljs script using cljs-aws."
[& args]
(go
(util/override-endpoint-with-env)
(throw-or-print (<! (kinesis/create-stream {:stream-name stream-name, :shard-count 1})))
(throw-or-print (<! (kinesis/list-streams {})))
(throw-or-print (<! (kinesis/describe-stream {:stream-name stream-name})))
(println "Waiting for stream to be created...")
(loop []
(<! (timeout 3000))
(let [stream-status (-> (<! (kinesis/describe-stream {:stream-name stream-name}))
:stream-description
:stream-status)]
(println "Stream is" stream-status)
(when (= stream-status "CREATING") (recur))))
(throw-or-print (<! (kinesis/put-record {:stream-name stream-name
:data "my data"
:partition-key (str (random-uuid))})))
(throw-or-print (<! (kinesis/put-records {:stream-name stream-name
:records [{:partition-key "x5h2ch", :data "foo"}
{:partition-key "x5j3ak", :data "quux"}]})))
(let [shard-iterator (-> (<! (kinesis/get-shard-iterator {:stream-name stream-name
:shard-id "shardId-000000000000"
:shard-iterator-type "TRIM_HORIZON"}))
(throw-or-print)
:shard-iterator)]
(throw-or-print (<! (kinesis/get-records {:shard-iterator shard-iterator}))))
(throw-or-print (<! (kinesis/delete-stream {:stream-name stream-name})))))
(set! *main-cli-fn* -main)