Access commonly used credentials quickly in irb
I often deal with multiple Amazon AWS accounts in irb, and grew tired of copying and pasting my credentials, so I added code to my ~/.irbrc
to make them available from a constant. Here is the relevant chunk of my irbrc
(explanation follows):
I load the credentials from a separate yaml file, with the keys as symbols (I’ll explain why in a sec):
The yaml is parsed and loaded in to an OpenCascade
from the Hashery gem, which works like ruby’s builtin OpenStruct, but provides deep ‘structing’ of the source hash. Since it requires symbols as keys, I store the keys as symbols in the yaml to avoid an ugly symbolize_keys
step.
Now, inside irb, I can access the credentials with:
EC2.account_a.access_key_id EC2.account_b.secret_access_key
Since I use RVM gemsets for almost everything, I’m often switching between gemsets, some of which have not had an irb session. To handle that case, I have the force_require
method that will automatically install missing gems.