Last active
December 2, 2021 17:45
-
-
Save digash/23ce503c71cd8bb93ae57212f3ece2dd to your computer and use it in GitHub Desktop.
Read all meta-data on AWS EC2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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