First post of the year! To talk about clojure, of course. I’ve written (pt_br) about clojure macros before. And yes, it is really powerful.
I’m using macros to help me setting up a connection with Amazon SimpleDB to do some small administrative tasks such as listing domains, creating domains, counting items in a domain, etc.
SimpleDB hasn’t a console, so you have interact with it using a pure html + js application provided by AWS, or do it by hand. I do prefer doing it by my own :). Then I created de following macro:
It saves the work of configuring the appropriate log levels as well as creating SimpleDB client using rummage (a SimpleDB client by @cemerick).
And why a macro? Because in some extent you can see a macro as a code template, just like Velocity or String Template. So what this macro does is just “typing” all this code on my REPL namespace, than the defined functions and vars are automatic available in the user
namespace.
Using it is simple:
(boot-sdb)
“types” all the code for you, then you can call the functions like (lsd)
to get the list of domains in your SimpleDB.
If take a closer look you may notice a function call to (env "AWS_KEYID")
. It simply gets the environment variables set with your credentials.
You can extend the macro to have any admin task you may need. Note that the *sdbconf*
will become available, so you can call rummage directly without having to configure all again.
That is it. Clojure is smart!