Advertisement
NLinker

Example for calling SQS with amazonka

Sep 16th, 2016
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {-# LANGUAGE OverloadedStrings #-}
  2.  
  3. import           Data.HashMap.Strict          (toList)
  4. import           Control.Monad.Trans.Resource (runResourceT)
  5. import           Control.Monad.IO.Class       (MonadIO, liftIO)
  6. import           Control.Lens                 ((&),(.~),(^.),(?~))
  7. import           Data.ByteString              (pack)
  8. import           Network.AWS                  (runAWS, send, LogLevel (Debug), Logger, Region (Oregon), newLogger)
  9. import           Network.AWS.SQS
  10. import           Network.AWS.Auth
  11. import           Network.AWS.Env
  12. import           System.IO                    (stdout)
  13. import qualified Data.Map as M
  14.  
  15. ---- libraries used ----
  16. -- amazonka
  17. -- amazonka-sqs
  18. -- lens
  19. -- containers
  20. -- unordered-containers
  21. -- resourcet
  22. -- transformers
  23. -- bytestring
  24.  
  25. run :: IO ()
  26. run = do
  27.   let queueUrl = "TODO"
  28.   env <- buildAwsEnv
  29.   r <- liftIO $ runResourceT $ runAWS env $ send $
  30.     getQueueAttributes queueUrl & gqaAttributeNames .~ attributes
  31.   print $ M.fromList $ toList $ r ^. gqarsAttributes
  32.  
  33. attributes :: [QueueAttributeName]
  34. attributes =
  35.   [ ApproximateNumberOfMessages
  36.   , ApproximateNumberOfMessagesDelayed
  37.   , ApproximateNumberOfMessagesNotVisible
  38.   , CreatedTimestamp
  39.   , DelaySeconds
  40.   , LastModifiedTimestamp
  41.   , MaximumMessageSize
  42.   , MessageRetentionPeriod
  43.   , Policy
  44.   , QueueARN
  45.   , ReceiveMessageWaitTimeSeconds
  46.   , RedrivePolicy
  47.   , VisibilityTimeout
  48.   ]
  49.  
  50. buildAwsEnv :: IO Env
  51. buildAwsEnv = do
  52.   logger <- newLogger Debug stdout
  53.   env <- newEnv Oregon $ FromKeys
  54.     (AccessKey "TODO")
  55.     (SecretKey "TODO")
  56.   return $ envWithLog logger env
  57.   where
  58.     envWithLog :: Logger -> Env -> Env
  59.     envWithLog logger env = env & envLogger .~ logger
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement