Menu
Amazon Simple Queue Service
API Reference (API Version 2012-11-05)

SendMessageBatch

Delivers up to ten messages to the specified queue. This is a batch version of SendMessage. For a FIFO queue, multiple messages within a single batch are enqueued in the order they are sent.

The result of sending each message is reported individually in the response. Because the batch request can result in a combination of successful and unsuccessful actions, you should check for batch errors even when the call returns an HTTP status code of 200.

The maximum allowed individual message size and the maximum total payload size (the sum of the individual lengths of all of the batched messages) are both 256 KB (262,144 bytes).

Important

A message can include only XML, JSON, and unformatted text. The following Unicode characters are allowed:

#x9 | #xA | #xD | #x20 to #xD7FF | #xE000 to #xFFFD | #x10000 to #x10FFFF

Any characters not included in this list will be rejected. For more information, see the W3C specification for characters.

If you don't specify the DelaySeconds parameter for an entry, Amazon SQS uses the default value for the queue.

Some actions take lists of parameters. These lists are specified using the param.n notation. Values of n are integers starting from 1. For example, a parameter list with two elements looks like this:

&Attribute.1=this

&Attribute.2=that

Request Parameters

For information about the parameters that are common to all actions, see Common Parameters.

QueueUrl

The URL of the Amazon SQS queue to which batched messages are sent.

Queue URLs are case-sensitive.

Type: String

Required: Yes

SendMessageBatchRequestEntry.N

A list of SendMessageBatchRequestEntry items.

Type: Array of SendMessageBatchRequestEntry objects

Required: Yes

Response Elements

The following elements are returned by the service.

BatchResultErrorEntry.N

A list of BatchResultErrorEntry items with error details about each message that can't be enqueued.

Type: Array of BatchResultErrorEntry objects

SendMessageBatchResultEntry.N

A list of SendMessageBatchResultEntry items.

Type: Array of SendMessageBatchResultEntry objects

Errors

For information about the errors that are common to all actions, see Common Errors.

AWS.SimpleQueueService.BatchEntryIdsNotDistinct

Two or more batch entries in the request have the same Id.

HTTP Status Code: 400

AWS.SimpleQueueService.BatchRequestTooLong

The length of all the messages put together is more than the limit.

HTTP Status Code: 400

AWS.SimpleQueueService.EmptyBatchRequest

The batch request doesn't contain any entries.

HTTP Status Code: 400

AWS.SimpleQueueService.InvalidBatchEntryId

The Id of a batch entry in a batch request doesn't abide by the specification.

HTTP Status Code: 400

AWS.SimpleQueueService.TooManyEntriesInBatchRequest

The batch request contains more entries than permissible.

HTTP Status Code: 400

AWS.SimpleQueueService.UnsupportedOperation

Error code 400. Unsupported operation.

HTTP Status Code: 400

Example

The following example SendMessageBatch request sends two messages to the queue. You must URL-encode the entire URL. However, in this example only the message body is URL-encoded to make the example easier to read. How you structure the AUTHPARAMS depends on how you are signing your API request. For information about AUTHPARAMS in Signature Version 4, see Examples of Signed Signature Version 4 Requests in the Amazon Web Services General Reference.

Sample Request

http://sqs.us-east-2.amazonaws.com/123456789012/testQueue/
?Action=SendMessageBatch
&SendMessageBatchRequestEntry.1.Id=test_msg_001
&SendMessageBatchRequestEntry.1.MessageBody=test%20message%20body%201
&SendMessageBatchRequestEntry.2.Id=test_msg_002
&SendMessageBatchRequestEntry.2.MessageBody=test%20message%20body%202
&SendMessageBatchRequestEntry.2.DelaySeconds=60
&SendMessageBatchRequestEntry.2.MessageAttribute.1.Name=test_attribute_name_1
&SendMessageBatchRequestEntry.2.MessageAttribute.1.Value.StringValue=test_attribute_value_1
&SendMessageBatchRequestEntry.2.MessageAttribute.1.Value.DataType=String
&Version=2012-11-05
&Expires=2020-05-05T22%3A52%3A43PST
&AUTHPARAMS

Sample Response

<SendMessageBatchResponse>
<SendMessageBatchResult>
    <SendMessageBatchResultEntry>
        <Id>test_msg_001</Id>
        <MessageId>0a5231c7-8bff-4955-be2e-8dc7c50a25fa</MessageId>
        <MD5OfMessageBody>0e024d309850c78cba5eabbeff7cae71</MD5OfMessageBody>
    </SendMessageBatchResultEntry>
    <SendMessageBatchResultEntry>
        <Id>test_msg_002</Id>
        <MessageId>15ee1ed3-87e7-40c1-bdaa-2e49968ea7e9</MessageId>
        <MD5OfMessageBody>7fb8146a82f95e0af155278f406862c2</MD5OfMessageBody>
        <MD5OfMessageAttributes>295c5fa15a51aae6884d1d7c1d99ca50</MD5OfMessageAttributes>
    </SendMessageBatchResultEntry>
</SendMessageBatchResult>
<ResponseMetadata>
    <RequestId>ca1ad5d0-8271-408b-8d0f-1351bf547e74</RequestId>
</ResponseMetadata>
</SendMessageBatchResponse>

See Also

For more information about using this API in one of the language-specific AWS SDKs, see the following: