Skip to content

Instantly share code, notes, and snippets.

@digash
Last active December 2, 2021 17:45
Show Gist options
  • Save digash/23ce503c71cd8bb93ae57212f3ece2dd to your computer and use it in GitHub Desktop.
Save digash/23ce503c71cd8bb93ae57212f3ece2dd to your computer and use it in GitHub Desktop.
Read all meta-data on AWS EC2
#!/bin/env bb
(let [cgb #(->> % (cons "http://169.254.169.254/latest") (str/join "/") curl/get :body)
try-json #(try (json/parse-string %) (catch Exception _ %))
dir? #(str/ends-with? (last %) "/")
paths (fn [p] (->> (cgb p)
str/split-lines
(map #(->> (str/split % #"=") first (conj p)))))
trimlslash #(str/replace % #"/$" "")]
(json/generate-stream
(->> (tree-seq dir? paths ["meta-data/"])
(filter (comp not dir?))
(map #(map trimlslash %))
(reduce #(assoc-in %1 %2 (try-json (cgb %2))) {}))
*out* {:pretty true}))
(flush)
#!/bin/env bb
(let [cgb #(-> % curl/get :body)
dir? #(str/ends-with? % "/")
paths (fn [p] (->> (cgb p)
str/split-lines
(map #(->> (str/split % #"=") first (str p)))))]
(doseq [p (->> (tree-seq dir? paths "http://169.254.169.254/latest/meta-data/")
(filter (comp not dir?))
sort)]
(println p \tab (cgb p))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment