amazonica icon indicating copy to clipboard operation
amazonica copied to clipboard

Suggestion: with-region

Open lvh opened this issue 7 years ago • 0 comments

There is an obvious way to spell with-region in 3rd party code:

(defmacro with-region
  [region & body]
  `(amazonica.core/with-credential
     {:endpoint (name ~region)}
     ~@body))

However, this has a subtle bug: if you nest with-credential calls, with-region will override previously set credentials. Arguably, the real thing to do here is to set credentials via env vars or something so the problem doesn't happen, but, alternatively:

(defmacro with-region
  [region & body]
  `(amazonica.core/with-credential
     (assoc @#'amazonica.core/*credentials* :endpoint (name ~region))
     ~@body))

You can do this in third-party code, but only with the weird @#' visibility-bypass hack.

lvh avatar Apr 05 '17 14:04 lvh