Sending Messages in Amazon SQS - AWS SDK for Ruby

Sending Messages in Amazon SQS

The following example sends the message “Hello world” through the Amazon SQS queue with the URL URL in the us-west-2 region.

require 'aws-sdk-sqs' # v2: require 'aws-sdk' sqs = Aws::SQS::Client.new(region: 'us-west-2') sqs.send_message(queue_url: URL, message_body: 'Hello world')

The following example sends the messages “Hello world” and “How is the weather?” through the Amazon SQS queue with the URL URL in the us-west-2 region.

Note

If your queue is a FIFO queue, you must include a message_group_id parameter in addition to the id and message_body parameters.

require 'aws-sdk-sqs' # v2: require 'aws-sdk' sqs = Aws::SQS::Client.new(region: 'us-west-2') sqs.send_message_batch({ queue_url: URL, entries: [ { id: 'msg1', message_body: 'Hello world' }, { id: 'msg2', message_body: 'How is the weather?' } ], })