aws 2022-08-04

are there any examples of aws sqs using cognitect aws-api?

I would like to reach out an example for retrieving messages from time to time

(require '[promesa.core :as p])

(defonce consume-sqs-scheduler-running
  (atom true))

(def consume-sqs-scheduler
  (let [{::keys [event-pull-seconds]} config]
    (p/loop []
      (p/delay (* 1000 event-pull-seconds))
      (when @consume-sqs-scheduler-running
        (handle-sqs-data (pull-sqs-data! config))
        #_(println ::RUN!))
      (p/recur))))

SQS client has built-in long-polling support if max 20sec interval is OK for you https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/examples-sqs-long-polling.html

Sorry, I don’t have an example how to use that with cognitect aws-api but just wanted to point out this as an option. 🙂

Oh wait… cognitect aws-api uses the API directly and there’s no “official” aws-client involved.. So you’ll probably need to build the delay mechanism yourself. Your example with promesa looks like a an OK starting point. It’s very simple and probably works. If you you need something more robust I’d look into quarts (maybe a bit overkill), tea-time or similar scheduler.

Or.. since you’re on AWS.. it’s also possible to schedule a lambda to periodically read the queue

👍 1

Actually.. it would be kinda interesting if someone has figured out how to do long-polling with cognitect aws-api

I would go for Lambda. Typically you want consume message & dead letter queue. This is very easy to setup with Lambda.

https://github.com/RutledgePaulV/piped is an SQS client implemented with aws-api, might be worth checking out the source code

if it's not possible, I'll do something like this