--- amazon.php5.inc.orig	2009-11-12 13:03:26.064224512 -0500
+++ amazon.php5.inc	2009-11-12 14:47:34.143723018 -0500
@@ -19,12 +19,12 @@
    *
    */
   $_amazon_search_amazon_shop_URI =
-    array('US'=>'http://webservices.amazon.com/onca/xml?Service='.AMAZON_SEARCH_AMAZON_SERVICE,
-          'UK'=>'http://webservices.amazon.co.uk/onca/xml?Service='.AMAZON_SEARCH_AMAZON_SERVICE,
-          'DE'=>'http://webservices.amazon.de/onca/xml?Service='.AMAZON_SEARCH_AMAZON_SERVICE,
-          'JP'=>'http://webservices.amazon.co.jp/onca/xml?Service='.AMAZON_SEARCH_AMAZON_SERVICE,
-          'FR'=>'http://webservices.amazon.fr/onca/xml?Service='.AMAZON_SEARCH_AMAZON_SERVICE,
-          'CA'=>'http://webservices.amazon.ca/onca/xml?Service='.AMAZON_SEARCH_AMAZON_SERVICE
+    array('US'=>'http://ecs.amazon.com/onca/xml?Service='.AMAZON_SEARCH_AMAZON_SERVICE,
+          'UK'=>'http://ecs.amazon.co.uk/onca/xml?Service='.AMAZON_SEARCH_AMAZON_SERVICE,
+          'DE'=>'http://ecs.amazon.de/onca/xml?Service='.AMAZON_SEARCH_AMAZON_SERVICE,
+          'JP'=>'http://ecs.amazon.co.jp/onca/xml?Service='.AMAZON_SEARCH_AMAZON_SERVICE,
+          'FR'=>'http://ecs.amazon.fr/onca/xml?Service='.AMAZON_SEARCH_AMAZON_SERVICE,
+          'CA'=>'http://ecs.amazon.ca/onca/xml?Service='.AMAZON_SEARCH_AMAZON_SERVICE
           );
 
   /**
@@ -302,7 +302,43 @@
   */
   function amazon_get_XML($Amazon_Params) {
     $AmazonXML = '';
-    $url = amazon_search_RESTURI($Amazon_Params);
+  $url = amazon_search_RESTURI($Amazon_Params);
+  // This section handles signing the request.
+  // Add GMT timestamp - Required for Signing Request    
+  $Amazon_Params["Timestamp"] = gmdate("Y-m-d\TH:i:s\Z");
+  // Additional Parameters
+  $method = "GET";
+  // Find Locale And Then Set Appropriate Host Variable - If Not Set Use US
+  $locale_amz_set=variable_get('amazon_locale',"");
+  	if $locale_amz_set="US" { $host = "ecs.amazonaws.com"; }
+        elseif $locale_amz_set="UK" { $host = "ecs.amazonaws.co.uk"; }
+        elseif $locale_amz_set="DE" { $host = "ecs.amazonaws.de"; }
+        elseif $locale_amz_set="JP" { $host = "ecs.amazonaws.co.jp"; }
+        elseif $locale_amz_set="FR" { $host = "ecs.amazonaws.fr"; }
+        elseif $locale_amz_set="CA" { $host = "ecs.amazonaws.ca"; }
+	else { $host = "ecs.amazonaws.com"; }	
+  $uri = "/onca/xml";
+  
+  // sort the parameters
+  ksort($Amazon_Params);
+  // create the canonicalized query
+  $canonicalized_query = array();
+  foreach ($Amazon_Params as $param=>$value) {
+  		$param = str_replace("%7E", "~", rawurlencode($param));
+  		$value = str_replace("%7E", "~", rawurlencode($value));
+ 		$canonicalized_query[] = $param."=".$value;
+  		}
+ 	$canonicalized_query = implode("&", $canonicalized_query);
+  // create the string to sign
+  $string_to_sign = $method."\n".$host."\n".$uri."\n".$canonicalized_query;  
+  // calculate HMAC with SHA256 and base64-encoding
+  $secret_access_key=variable_get('amazon_aws_secret_access_key',"");
+  $signature = base64_encode(hash_hmac("sha256", $string_to_sign, $secret_access_key, True));  
+  // encode the signature for the request
+	$signature = str_replace("%7E", "~", rawurlencode($signature));
+  // create request
+  $url = "http://".$host.$uri."?".$canonicalized_query."&Signature=".$signature;
+   
     // Obviously this will be switched for an equivalent Drupal function
     // Nope. drupal_http_request() strips the doctype tag at the start of the XML, making it useless
     $ch = curl_init($url);
@@ -343,4 +379,4 @@
     return _amazon_items_array_from_DOM($_amazon_search_amazonDOM);
   }
 
-?>
\ No newline at end of file
+?>
