This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-10-05
Channels
- # announcements (14)
- # aws (7)
- # babashka (28)
- # beginners (16)
- # calva (2)
- # cider (1)
- # clj-commons (8)
- # clj-kondo (29)
- # clojure (213)
- # clojure-europe (39)
- # clojure-losangeles (2)
- # clojure-norway (9)
- # clojure-spec (2)
- # clojurescript (11)
- # community-development (1)
- # conjure (2)
- # cursive (6)
- # datalevin (2)
- # datomic (8)
- # emacs (29)
- # events (1)
- # fulcro (22)
- # graalvm (14)
- # improve-getting-started (1)
- # jobs (1)
- # lambdaisland (5)
- # leiningen (4)
- # lsp (7)
- # malli (13)
- # meander (11)
- # membrane (13)
- # off-topic (23)
- # polylith (9)
- # re-frame (4)
- # reagent (7)
- # reitit (6)
- # releases (2)
- # sql (58)
- # testing (8)
- # tools-deps (18)
- # web-security (2)
Hi there. I'm writing a bb script using the AWS pod. When the script terminates (because of Ctrl-C) I'd like to remove some resources that were made during the script's execution. I do this in a shutdown hook. However, the pod process terminates before I have a chance to call it. I understand that this is because shutdown hooks run in a nondeterministic order. Has anyone found a way around this?
Interesting... When you have a chance, you could also take a look at https://github.com/grzm/awyeah-api which is a rewrite of Cognitect's AWS API for bb
Babashka v0.9.163-SNAPSHOT REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.
user=> (sun.misc.Signal/handle
(sun.misc.Signal. "INT")
(reify sun.misc.SignalHandler
(handle [_ _]
(println "caught sigint")
;; do something
(Thread/sleep 3000)
(println "Finishing")
(System/exit 0))))
#object[babashka.impl.sigint_handler$handle_sigint_BANG_$reify__30967 0xb2ffbfb "babashka.impl.sigint_handler$handle_sigint_BANG_$reify__30967@b2ffbfb"]
user=> ^Ccaught sigint
Finishing
I'd prefer to use a pod-based solution (I like the self-contained nature of a pod-based script) so I'm pursuing Crispin's suggestion. However, I end up in the same situation. My guess is that bb and the AWS pod receive SIGINT simultaneously, so I get this when I'm attempting to make AWS calls from my signal handler:
Exception in thread "SIGINT handler" java.io.IOException: Stream closed
at java.lang.ProcessBuilder$NullOutputStream.write(ProcessBuilder.java:442)
at java.io.OutputStream.write(OutputStream.java:157)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:81)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:142)
at babashka.pods.impl$write.invokeStatic(impl.clj:23)
at babashka.pods.impl$invoke.invokeStatic(impl.clj:109)
at babashka.pods.impl$bencode__GT_vars$fn__27160$fn__27165.doInvoke(impl.clj:134)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at sci.lang.Var.invoke(lang.cljc:182)
The idea of my script is to 'tail' an SNS topic, by making an SQS queue, subscribing the topic to the queue, doing some processing on the stuff coming off the queue, and then deleting the queue when the user hits Ctrl-C
> (I like the self-contained nature of a pod-based script) you can get this with deps too:
(require '[babashka.deps :as deps])
(deps/add-deps '{:deps {com.cognitect.aws/endpoints {:mvn/version "1.1.12.206"}
com.cognitect.aws/s3 {:mvn/version "822.2.1109.0"}
com.grzm/awyeah-api {:git/url ""
:git/sha "0fa7dd51f801dba615e317651efda8c597465af6"}}})
(require '[com.grzm.awyeah.client.api :as aws])
;; etc
Yes, that's what I mean. I didn't realise you could do that! I'll give awyeah a try, then
Nice! I'll ping @U0EHU1800 here too since I can imagine he would like to know his library is getting some good use
Hi, I'm trying to decrypt something using the buddy pod, but I'm getting clojure.lang.ExceptionInfo: No matching method init found taking 3 args for class javax.crypto.Cipher
This works on clj, but not on bb. In the docs it says that jwk->private-key
returns a byte-array and decrypt
takes a byte array, so it should theoretically work the same on both if I pass the return of one to the other, right?
(defn- jwk->keys [jwk]
{:public-key (keys/jwk->public-key jwk),
:private-key (keys/jwk->private-key jwk)})
(jwt/decrypt encrypted
(:private-key (jwk->keys jwk))
{:alg :rsa-oaep, :enc :a128cbc-hs256})