我刚开始使用Clojurescript。我编写了一些clojurescript代码,以使用共享的aws凭证文件初始化S3客户端和列表存储桶。但是我的代码不起作用。
(defn -main [arg1 arg2]
(println "hello")
(let[ creds (new AWS/SharedIniFileCredentials #js{:profile "superman"})
_ (AWS/config.update creds)
; dump out the accesskey to check if it has the correct profile
_ (AWS/config.getCredentials (fn [err] (if (nil? err) (do
(println "its good")
(println AWS/config.credentials.accessKeyId)))))
s3 (new (.-S3 AWS ))
] (.listBuckets s3 (fn[err buckets] (println "err: " err) (println buckets) )) ))
上面的AWS / config.getCredentials确实选择了从(println AWS/config.credentials.accessKeyId)
中看到的正确配置文件。 listbuckets代码引发以下错误:
#object[NodeError TypeError [ERR_INVALID_ARG_TYPE]: The "key" argument must be of type string or an instance of Buffer, TypedArray, DataView, or KeyObject. Received undefined]
我有Google AWS开发工具包S3 clojuresript,是我发现的only link。我用它来配置S3客户端,但这似乎不起作用
我将不胜感激。
我检查了一下,问题似乎出在实例化S3客户端之前,SDK希望先设置凭据。
以下内容对我使用shadow-cljs的最小项目有效:
(ns server.main
(:require ["aws-sdk" :as aws]))
(defn main! []
(println "App loaded...")
(let [creds (aws/SharedIniFileCredentials. #js {:profile "example-profile"})
_ (set! (.-credentials aws/config) creds)
s3 (aws/S3.)]
(.listBuckets s3 (fn [err data]
(if err
(println "ERROR:" err)
(println "OK:" data))))))
当我运行它时:
$ node target/main.js
OK: #js {:Buckets #js [#js {:Name dummy-test-bucket, :CreationDate #inst "2019-05-05T17:32:17.000-00:00"} #js {:Name mydomain.com, :CreationDate #inst "2018-06-19T04:16:10.000-00:00"}], :Owner #js {:DisplayName username, :ID f63f30bc25ab3609b8d3b5be6b3a872dd2c9f7947b2d509e2338357d93e74f2}}