aristidb / aws

Amazon Web Services for Haskell
BSD 3-Clause "New" or "Revised" License
239 stars 108 forks source link

Question: how should one construct Sqs.QueueName when just receiving messages? #207

Open atcol opened 8 years ago

atcol commented 8 years ago

I notice that QueueName requires an account num -- where might I get this from? In the examples it's read from URLs that have been given as part of a queue creation response. If I haven't just created the queue then how might I get its URL? It's not obvious from the tests you have (because it's all test data e.g. read from URLs via withResource).

Probably related to the above question is that I get this error despite setting the correct environment variables:

SqsError {sqsStatusCode = Status {statusCode = 403, statusMessage = "Forbidden"}, sqsErrorCode = "SignatureDoesNotMatch", sqsErrorType = "Sender", sqsErrorMessage = "The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.", sqsErrorDetail = Nothing, sqsErrorMetadata = Nothing}

I have also tried the $HOME/.aws-keys route but get the same error.

import qualified Aws
import qualified Aws.Core
import qualified Aws.Sqs as SQS
import Control.Concurrent (threadDelay)
import Control.Error
import Control.Monad.IO.Class
import Data.Monoid
import Data.String
import qualified Data.Text.IO as T
import qualified Data.Text    as T
import qualified Data.Text.Read as TR
import Control.Monad (forM_, forM, replicateM)
import           System.IO

-- | Read a message from the queue
getMessages :: T.Text -- ^ name of the queue to read from
            -> String
getMessages name = do
  let queue = SQS.QueueName name "" -- account num is empty?
  cfg <- Aws.baseConfiguration
  let sqscfg = SQS.sqs Aws.Core.HTTP SQS.sqsEndpointEu False :: SQS.SqsConfiguration Aws.NormalQuery
  -- Next: visibility timeout, response attributes, count, user attr, QueueName, timeout
  r <- Aws.simpleAws cfg sqscfg $ SQS.ReceiveMessage (Just 60) [] (Just 1) [] queue Nothing
  case r of
      SQS.ReceiveMessageResponse t -> show $ head t

Thanks in advance for any help.