DEV Community

Discussion on: I am an AWS solution architect, Ask Me Anything AWS!

Collapse
jorgemasta profile image
Jorge Masta

Have you experienced problems with the Amazon Simple Queue Service (SQS)?

Collapse
andrewbrown profile image
Andrew Brown 🇨🇦 • Edited on

So here is me sending a message to SQS with a Lambda anytime a new record is inserted into DynamoDB. So I find the json object being passed along a bit verbose.

require 'aws-sdk-sqs'

def handler(event:, context:)
  puts 'events'
  puts event.inspect
  event['Records'].each do |record|
    if record['eventName'] == 'INSERT'
      url      = record['dynamodb']['NewImage']['github']['S']
      username = record['dynamodb']['NewImage']['username']['S']
      puts "url: #{url}"
      client = Aws::SQS::Client.new()
      resp = client.send_message({
        queue_url:    ENV['QueueUrl'],
        message_body: url,
        delay_seconds: 0,
        message_attributes: {
          "username" => {
            string_value: username,
            data_type: "String"
          }
        }
      })
      puts "message_id: #{resp.message_id}"
    end
  end
end

Having to pull your queue is feels slow and annoying. I'm used to Sidekiq which is super fast.
I normally provision an EC2 instance with Sidekiq and back it with ElastiCache Redis.

Though SQS as a dead simple straight forward queue is great but I generally miss all the plugins Sidekiq comes with.