Jan 6 / phoet

Heroku with ruby-aaws

The first step of migrating my Rails app to Heroku included only a reduced feature set.

I completely removed all parts dealing with the Amazon-API, because ruby-aaws could not be installed as a gem on Heroku. The ruby-aaws gem is build on Ruby >= 1.8.7 while Heroku is running 1.8.6 #fail.

I asked Ian Macdonald, the creator of ruby-aaws, if there might be a workaround for this problem. Ian told me that this should not be a blocker and pointed me to some things I should take care of.

How to make ruby-aaws run with 1.8.6

Here are the steps that I performed to get things running:

# install gemsonrails to freeze the gem into the app
sudo gem install gemsonrails
 
# go to your rails folder
cd rails/yourapp
 
# install gemsonrails for your app
gemsonrails
 
# freeze the app
rake gems:freeze GEM=ruby-aaws

This will freeze the gem into vendor/gems/. Then I removed the tests and the examples, because they are not necessary and contain code that won’t work.
The app won’t start up until I fixed some little load path error:

# vendor/gems/ruby-aaws-0.7.0/init.rb
# add amazon to the path
require_options = ["ruby-aaws", "ruby/aaws", "amazon"]

The ruby-aaws library expects some login-credentials for the Amazon-API which are usually stored in a ~/.amazonrc file. Since Heroku gives no access to a user home (at least I did not manage to get access to it), I worked around it by putting the file in the RAILS_ROOT and adding some glue code in Amazon::Config:

# vendor/gems/ruby-aaws-0.7.0/lib/amazon.rb
# add rails-file
config_files << File.join(RAILS_ROOT, '.amazonrc') if defined?(RAILS_ROOT)

The next thing to fix was the usage of String.bytesize, which is not available in 1.8.6:

string.gsub( /([^a-zA-Z0-9_.~-]+)/ ) do
  # replace .bytesize with .size
  '%' + $1.unpack( 'H2' * $1.size ).join( '%' ).upcase
end

Voilà!

Share and Enjoy:
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Twitter
  • DZone
  • Reddit
  • Slashdot
  • Tumblr
  • Yigg

5 Comments

leave a comment
  1. Corprew Reed / Jan 20 2010

    On rails 2.3.4, I had to use rake gems:unpack to follow these instructions rather than rake gems:freeze to get the specification file for the gem into YAML instead of ruby format.

    The loader for gems in vendor will only take the YAML format ( see vendor_gem_source_index.rb, line 50.)

    Probably a bug somewhere in the internals, but I thought I’d mention it here in case other people came across the same problem.

  2. admin / Jan 20 2010

    @Corprew your help is much appreciated!

    I did a little ajustment to the code myself, because there were some issues with other ruby versions:

        string.gsub( /([^a-zA-Z0-9_.~-]+)/ ) do
          '%' + $1.unpack( 'H2' * (Object::VERSION == "1.8.6" ? $1.size : $1.bytesize) ).join( '%' ).upcase
        end
  3. Franco / Feb 18 2010

    Great post. I never would have it working without this post thanks.

  4. phoet / Mar 27 2010

    I used a different approach for fixing the .amazonrc within my latest Rails 3 update:

    I included the amazon-aaws gem as is and just monkey-patched the .amazonrc stuff wihtin an initializer:

    http://github.com/phoet/basement_rails3/blob/master/config/initializers/monkey_patch.rb#L28

Trackbacks and Pingbacks

  1. ASIN vs ruby-aaws | #nofail
Leave a Comment

Fork me on GitHub