Exporting Scalr instance parameters as bash variables
Scalr.net is a very good service when it comes to hosting in the cloud, but it does have its little annoyances.
One of them is that you can’t access parameters passed to instances, as bash variables, and considering it has the Scalr scripts … they’re fairly pointless as parsing XML in bash is a nightmare.
So I wrote the following script which exports parameters passed to the instance as global bash variables.
#!/bin/bash source /usr/local/aws/lib/lib.sh export $( ruby <<RUBY require 'rexml/document' doc = REXML::Document.new('`ec2_get_option_query_env list-role-params`') doc.elements.each('//param') do |ele| puts ele.attributes["name"].upcase + "=" + ele.elements[1].text end RUBY )
Say you passed a “Twitter Api Key” parameter to your instance, this would be available as $TWITTER_API_KEY.
Pretty neat huh?