Topic: "Ruby on Rails Bible" Ch. 6 example Amazon AWS help

Hello,

I've been stuck on this for a day and a half now and I hope someone could help me out...
It really looks like I got everything right and I'm constantly getting a HTTP 400 back.
I installed ruby-aaws via gems:
user@localhost:~$ gem list

*** LOCAL GEMS ***

actionmailer (2.3.4)
actionpack (2.3.4)
activerecord (2.3.4)
activeresource (2.3.4)
activesupport (2.3.4)
amazon-ec2 (0.7.3)
builder (2.1.2)
highline (1.5.1)
hoe (2.3.3)
json_pure (1.2.0)
mime-types (1.16)
mysql (2.8.1)
rack (1.0.1)
rails (2.3.4)
rake (0.8.7)
ruby-aaws (0.7.0)
ruby-aws (1.2.0)
rubyforge (2.0.3)
xml-simple (1.0.12)

I have my ~/.amazonrc config file set up, in the seemingly correct format:
  key_id = 'my Amazon Key ID'
  secret_key_id = 'my secret amazon key id'
  cache = false
  locale = 'us'

And finally here in irb:
Loading development environment (Rails 2.3.4)
>> require 'amazon/aws/search'
=> ["Amazon"]
>> include Amazon::AWS
=> Object
>>   include Amazon::AWS::Search
=> Object
>> con=Request.new('--my key id -----', 'calibanorg-20' )
=> #<Amazon::AWS::Search::Request:0xb71d36cc @locale="us", @key_id="--my key id -----", @conn=nil, @cache=#<Amazon::AWS::Cache:0xb71d2560 @path="/tmp/amazon">, @user_agent="Ruby/Amazon/AWS 0.7.0", @tag="calibanorg-20", @encoding=nil, @config={}, @api=nil>
>> is = ItemSearch.new('Books', {'Keywords' => 'Ruby Programming'})
=> #<Amazon::AWS::ItemSearch:0xb71ca8b0 @response_group=#<Amazon::AWS::ResponseGroup:0xb71ca4dc @params={"ResponseGroup"=>"Large"}, @list=[:Large]>, @params={"Operation"=>"ItemSearch", "Keywords"=>"Ruby Programming", "SearchIndex"=>"Books"}, @kind="ItemSearch">
>> resp=con.search(is)
Amazon::AWS::HTTPError: HTTP response code 400
    from /var/lib/gems/1.8/gems/ruby-aaws-0.7.0/lib/amazon/aws.rb:170:in `get_page'
    from /var/lib/gems/1.8/gems/ruby-aaws-0.7.0/lib/amazon/aws/search.rb:305:in `search'
    from (irb):6

My only clue, I think, is up there @config{}... its nil.  Thought it should contain my secret_key_id from the config file, .amazonrc. 
Help me, Obi-one-kinobis...

Re: "Ruby on Rails Bible" Ch. 6 example Amazon AWS help

The force is strong with you...

LOL ok, but seriously, I do indeed hate when the code in a book doesn't quite work as beautifully as it ideally should... Running into that with JavaScript in a book at the moment.

I do have this particular book though, and haven't played with it yet. Ok, so where is the value of @config stored? In a controller I assume?

Re: "Ruby on Rails Bible" Ch. 6 example Amazon AWS help

Here's my /etc/amazonrc (I put in in /etc/ and not ~/).  Its a little different from yours.  Try that. 

[global]
locale = 'us'
cache = false
key_id = 'XXXXX'
secret_key_id = 'YYYYYY'

[us]
associate = 'ZZZ-20'

Also, if you're on a Mac with Leopard, you'll have to use the following fix:
MacOS X Leopard openssl doesn't support SHA-256 message digests, so you can't authenticate a call to AAWS.  You have to replace openssl with the following HMAC gem and change the search.rb file to use the new functions 1) add the ruby-hmac gem  (version 0.3.2) 2) In aws' search.rb, modify the sign method to be the following (changing
two lines of code) from https://pastee.org/7pfay

Good luck!

Re: "Ruby on Rails Bible" Ch. 6 example Amazon AWS help

I am facing the exact same problem and have wasted days without any success. any help pls.

Re: "Ruby on Rails Bible" Ch. 6 example Amazon AWS help

I have this exact same error on a window machine.

Error body in the request returns :
The Request must contain the parameter Signature

which I take to to mean that my secret_key_id isn't be read.

Where does this .amazonrc file actually go.

All of the tutorials are for a linux machine.

My path for my project is C:\InstantRails-2.0\rail_apps\book_shelf

and my path for ruby-aaws-0.7.0 is
C:\InstantRails-2.0\ruby\lib\ruby\gems\1.8\gems\ruby-aaws-0.7.0

I've created a file dir ~\.amazonrc and tried a couple spots:
1. in the ruby-aaws-0.7.0 root
2. C:\Users\Brett

I've tried it as etc\amazonrc as well

I created it as a .txt file in e texteditor and it looks like this

[global]
  key_id = 'My_Key'
  secret_key_id = 'my_secret_key'
  cache = false
  locale = 'us'
  encoding = 'iso-8859-15'
[us]
  associate = 'my_associate'

Error is HTTP 400

Been frustrating me all day.  Thanks for any help.

Thanks

Re: "Ruby on Rails Bible" Ch. 6 example Amazon AWS help

so far as I can see, your AMAZON-SEARCH-REQUEST @config{} ist empty-> so I think your .amazonrc-file won't read
correctly.

I have done following and It works fine:


1. create an amazon.rb-file in config/initializers
    ENV['AMAZONRCDIR'] = "#{RAILS_ROOT}/config/"

2. create .amazonrc-file in /config/
    dev_token = 'your dev_token'
    associate = 'your associate'
    email = 'your email-adress'
    password = 'xxxxxx'
    cache = false
    key_id = 'your key_id'
    secret_key_id = 'your secret_key_id'

3. start your rails-framework

4. amzon request

require 'amazon/aws'
require 'amazon/aws/search'
include Amazon::AWS
include Amazon::AWS::Search

is = ItemSearch.new('Books', {'Keywords' => 'Ruby Programming'})
req = Request.new
rg = ResponseGroup.new( 'Large' )
req.search( is, rg )

and I get all info's :-)

Hope this help you a little bit....

I only installed ruby-aaws (0.7.0) ...

Re: "Ruby on Rails Bible" Ch. 6 example Amazon AWS help

You can also perform these operations without the hassle of creating the .amazonrc config file this way:

def config
  config = Amazon::Config.new
  config['key_id'] = 'YOURKEYID'
  config['secret_key_id'] = 'YourSecretKeyId'
  config['cache'] = false
  config['locale'] = 'us'
  config['encoding'] = 'UTF-8'
  config
end

#  OR:

def config2
  config = Amazon::Config.new <<-eos
    key_id = 'YOURKEYID'
    secret_key_id = 'YourSecretKeyId'
    cache = false
    locale = 'us'
    encoding = 'UTF-8'
  eos
end

ASSOCIATES_ID = 'yourassociateid-20'
KEY_ID = 'YOURKEYID'

is = ItemSearch.new('Books', {'Keywords' => 'Ruby Programming'})
is.response_group = ResponseGroup.new(:Large)

req = Request.new(KEY_ID, ASSOCIATES_ID, 'us', false)
req.instance_variable_set("@config", config) #  OR  config2

# Using the instance_variable_set method as in the previous code line 
# in this way is, of course, a hack.  But in my opinion, requiring that 
# devs provide some random config file which clutters up their home
# directory is silly.

#  So, if you don't like that, you can just access the config hash directly, like this:

req.config['key_id'] = KEY_ID
req.config['secret_key_id'] = 'YourSecretKeyId'
req.config['cache'] = false
req.config['locale'] = 'us'
req.config['encoding'] = 'UTF-8'

In fact, it's even easier than that.  Because you have already provided every option but the secret_key_id using the Request constructor (Request.new), you can simply specify just the secret_key_id for the existing Request.config, as follows:

is = ItemSearch.new('Books', {'Keywords' => 'Ruby Programming'})
is.response_group = ResponseGroup.new(:Large)

req = Request.new('YOURKEYID', 'yourassociateid-20', 'us', false)
req.config['secret_key_id'] = 'YourSecretKeyId'

Enjoy!  Good luck!
-Nels
http://nelsnelson.blogspot.com

Re: "Ruby on Rails Bible" Ch. 6 example Amazon AWS help

nelsnelson wrote:

In fact, it's even easier than that.  Because you have already provided every option but the secret_key_id using the Request constructor (Request.new), you can simply specify just the secret_key_id for the existing Request.config, as follows:

is = ItemSearch.new('Books', {'Keywords' => 'Ruby Programming'})
is.response_group = ResponseGroup.new(:Large)

req = Request.new('YOURKEYID', 'yourassociateid-20', 'us', false)
req.config['secret_key_id'] = 'YourSecretKeyId'

This worked! You just saved my day, thanks a lot.

I think I will try your config way coz leaving an id with a name of secret around looks crazy. Still not sure why .amazonrc in home directory is not working . I am guessing it has something to do with not having the correct path...