Skip to content

Instantly share code, notes, and snippets.

@ajkerrigan
Last active March 2, 2023 00:42
Show Gist options
  • Save ajkerrigan/1214d4632b9e46cfa77c024d7c12f23d to your computer and use it in GitHub Desktop.
Save ajkerrigan/1214d4632b9e46cfa77c024d7c12f23d to your computer and use it in GitHub Desktop.
Explore Cloud Custodian's Cache with VisiData

Explore Cloud Custodian's Cache with VisiData

By default, Cloud Custodian caches resource data for 15 minutes in ~/.cache/cloud-custodian.cache. This lets you run multiple policies or filters against the same resource data without having to hit cloud provider APIs each time.

Have you ever wanted to look inside that cache? You can!

The cache is a SQLite database, where keys and values are pickle-encoded blobs. We can use VisiData to deserialize those pickled blobs and expand them into a human-readable tabular view. c7n_cache.vdj is a sample replay file that executes a predefined set of commands. This should work for environments using Cloud Custodian's default cache settings, and can be run with:

vd -p /path/to/c7n_cache.vdj --replay-wait=2

(Where --replay-wait defines a number of seconds to wait between steps - you don't have to wait so long!)

asciicast

#!vd -p
{"longname": "open-file", "input": "$HOME/.cache/cloud-custodian.cache", "keystrokes": "o"}
{"sheet": "", "col": "", "row": "\u30adc7n_cache", "longname": "open-row", "input": "", "keystrokes": "Enter", "comment": "open current row with sheet-specific dive"}
{"sheet": "", "col": "", "row": "", "longname": "import-python", "input": "pickle", "keystrokes": "gCtrl+X", "comment": "import Python module in the global scope"}
{"sheet": "", "col": "", "row": "", "longname": "select-rows", "input": "", "keystrokes": "gs", "comment": "select all rows"}
{"sheet": "", "col": "key", "row": "", "longname": "setcol-expr", "input": "pickle.loads(cursorCol)", "keystrokes": "g=", "comment": "set current column for selected rows to result of Python expression"}
{"sheet": "", "col": "value", "row": "", "longname": "setcol-expr", "input": "pickle.loads(cursorCol)", "keystrokes": "g=", "comment": "set current column for selected rows to result of Python expression"}
{"sheet": "", "col": "value", "row": "", "longname": "unfurl-col", "input": "", "keystrokes": "zShift+M", "comment": "row-wise expand current column of lists (e.g. [2]) or dicts (e.g. {3}) within that column"}
{"sheet": "", "col": "", "row": "", "longname": "unselect-rows", "input": "", "keystrokes": "gu", "comment": "unselect all rows"}
{"sheet": "", "col": "value_key", "row": "", "longname": "hide-col", "input": "", "keystrokes": "-", "comment": "Hide current column"}
{"sheet": "", "col": "value_value", "row": "", "longname": "rename-col", "input": "value", "keystrokes": "^", "comment": "rename current column"}
{"sheet": "", "col": "value", "row": "", "longname": "expand-cols", "input": "", "keystrokes": "g(", "comment": "expand all visible columns of containers one level"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment