Hi, I am trying to use the SQS integration of jets.
I am able to automatically create on deploy the SQS queue, but I don’t know how to programmatically retrieve the SQS URL necessary to send the messages. There is a method for that or some kind of syntax sugar to send a message to the defined queue?
My current code:
class Event < Jets::Stack
sqs_queue(:events)
end
class EventJob < ApplicationJob
depends_on :event
sqs_event ref(:events)
def dig
puts "lol"
end
end
class EventJob < ApplicationJob
class_timeout 30 # must be less than or equal to the SQS queue default timeout
depends_on :event
sqs_event ref(:events)
def dig
puts "lol"
puts "received event payload: #{JSON.dump(event)}"
end
end
app/jobs/postman_job.rb:
class PostmanJob < ApplicationJob
include Jets::AwsServices
iam_policy "sqs"
def deliver
queue_url = Event.lookup(:events_url)
message_body = JSON.dump({"test": "hello world"})
sqs.send_message(
queue_url: queue_url,
message_body: message_body,
)
end
end
The Event.lookup(:events_url) is looking up the url via the CloudFormation output in the created Event shared resource stack.
Note, take care not to send a message to the same queue in the same method that is being used as the lambda trigger. It’ll cause an infinite loop, and you’ll eventually exhaust the free lambda tier.