        (generate-query-string query-params)))
 
 (defn- generate-signature [method uri query-params]
-  (let [url (URL. uri)
+  (let [query-params (into (sorted-map) query-params)
+        url (URL. uri)
         host (lower-case (.getHost url))
         path (get-path url)
         data (url-to-sign method host path query-params)]

   [javax.crypto.spec SecretKeySpec]
   [org.apache.commons.codec.binary Base64]
   [org.joda.time DateTime DateTimeZone]))


(def ^:const hmac-sha256-algorithm  "HmacSHA256")
(def ^:const new-line "\n")

  [method uri params]
  (let [query-params (merge params auth-params)
        signature (generate-signature method uri query-params)
        query-string (generate-query-string (merge {"Signature" signature} query-params))]
    (str uri "?" query-string)))

;(clj-http.client/get (build-url "get" "https://ec2.eu-west-1.amazonaws.com" {"Version" "2013-10-01" "Action" "DescribeSecurityGroups" }) {:throw-exceptions false})
