Created
February 1, 2011 22:45
-
-
Save pbrisbin/806888 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module AWSTest where | |
| import Network.HTTP.Base | |
| import Network.AWS.AWSConnection | |
| import Network.AWS.AWSResult | |
| import Network.AWS.Authentication | |
| import Data.List (intercalate) | |
| import Data.ByteString.Lazy (empty) | |
| -- | A convenience synonymc | |
| type Query = [(String,String)] | |
| -- | A test query | |
| myQuery :: Query | |
| myQuery = [ ("Service" , "AWSECommerceService" ) | |
| , ("Timestamp" , timeStamp ) | |
| , ("IdType" , "ASIN" ) | |
| , ("ItemId" , "159184021X" ) | |
| , ("Operation" , "ItemLookup" ) | |
| , ("ResponseGroup", "Medium,ItemAttributes,OfferFull") | |
| ] | |
| where | |
| -- | Builds a query string from the above | |
| queryString :: Query -> String | |
| queryString = ("?"++) . intercalate "&" . map (\(x,y) -> x ++ "=" ++ y) | |
| -- | My account info | |
| accessKey = "AKIAIO5SDDRP3574OXRQ" | |
| secretKey = "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" | |
| -- | Expiration time in the AWS TimeStamp format | |
| timeStamp = "2012-01" | |
| -- | For passing to preSignedURI | |
| -- | |
| -- > date -d "01/01/2012" +%s | |
| -- | |
| timeInSeconds = 1325394000 | |
| -- | Connection info | |
| awsConnection :: AWSConnection | |
| awsConnection = AWSConnection | |
| { awsHost = "webservices.amazon.com" | |
| , awsPort = 80 | |
| , awsAccessKey = accessKey | |
| , awsSecretKey = secretKey | |
| } | |
| -- | In theory, this should build the right url for an AWSEcommerce | |
| -- query even though it's meant for S3 actions | |
| myAction :: S3Action | |
| myAction = S3Action | |
| { s3conn = awsConnection | |
| , s3bucket = "onca" | |
| , s3object = "xml" | |
| , s3query = queryString myQuery | |
| , s3metadata = [] | |
| , s3body = empty | |
| , s3operation = GET | |
| } | |
| -- | The url looks good but amazon just says: "the signature we | |
| -- calculated doesn't match..." | |
| main = print $ preSignedURI myAction timeInSeconds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment