Hey guys probably an easy one, but can’t seem to f...
# help
g
Hey guys probably an easy one, but can’t seem to find it. How I can access the
queue
-url from within a sqs consumer? I would like to add an other message to the queue when the lambda is finished - I would like to chain commands this way. So I’m looking to achieve the following functionality . Unfortunately this doesn’t work since
Property 'setDefaultFunctionProps' does not exist on type 'Queue'.
Copy code
const queue = new sst.Queue(this, "Queue", {
      consumer: {
        function: "src/consumer.main",
        consumerProps: {
          batchSize: 1,
        },
      },
    })

    queue.setDefaultFunctionProps({
      environment: { queueUrl: queue.sqsQueue.queueUrl },
    })
a
There is a property in
event.Records
that you can use which AWS sends, you get the ARN of the queue in
eventSourceARN
, https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html
not sure if it helps though
g
thanks for the idea @Arpad. Yes I can use that to compute the sqs queue url for sure. Doesn’t seems like the prettiest solution tho, but it’ll work for now 💪
a
It seems like you can create the function separately with
new Function(...)
and pass that function as consumer
so you can create the queue, create the function, then addConsumer to the queue
g
So for future reference, the final solution was this:
Copy code
const queue = new sst.Queue(this, "Queue", {})

    queue.addConsumer(this, {
      function: {
        handler: "src/consumer.main",
        environment: {
          queueUrl: queue.sqsQueue.queueUrl,
        },
        permissions: [queue],
      },

      consumerProps: {
        batchSize: 1,
      },
    })
a
looks great!
don't forget to add a dead letter queue in case some of your messages can't be processed haha, got bit in the ass once for this