SendMessageBatch
You can use SendMessageBatch
to send up to 10 messages to the specified
queue by assigning either identical or different values to each message (or by not
assigning values at all). 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 KiB (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.
Request Syntax
{
"Entries": [
{
"DelaySeconds": number
,
"Id": "string
",
"MessageAttributes": {
"string
" : {
"BinaryListValues": [ blob
],
"BinaryValue": blob
,
"DataType": "string
",
"StringListValues": [ "string
" ],
"StringValue": "string
"
}
},
"MessageBody": "string
",
"MessageDeduplicationId": "string
",
"MessageGroupId": "string
",
"MessageSystemAttributes": {
"string
" : {
"BinaryListValues": [ blob
],
"BinaryValue": blob
,
"DataType": "string
",
"StringListValues": [ "string
" ],
"StringValue": "string
"
}
}
}
],
"QueueUrl": "string
"
}
Request Parameters
For information about the parameters that are common to all actions, see Common Parameters.
The request accepts the following data in JSON format.
- Entries
-
A list of
SendMessageBatchRequestEntry
items.Type: Array of SendMessageBatchRequestEntry objects
Required: Yes
- QueueUrl
-
The URL of the Amazon SQS queue to which batched messages are sent.
Queue URLs and names are case-sensitive.
Type: String
Required: Yes
Response Syntax
{
"Failed": [
{
"Code": "string",
"Id": "string",
"Message": "string",
"SenderFault": boolean
}
],
"Successful": [
{
"Id": "string",
"MD5OfMessageAttributes": "string",
"MD5OfMessageBody": "string",
"MD5OfMessageSystemAttributes": "string",
"MessageId": "string",
"SequenceNumber": "string"
}
]
}
Response Elements
If the action is successful, the service sends back an HTTP 200 response.
The following data is returned in JSON format by the service.
- Failed
-
A list of
BatchResultErrorEntry
items with error details about each message that can't be enqueued.Type: Array of BatchResultErrorEntry objects
- Successful
-
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.
- BatchEntryIdsNotDistinct
-
Two or more batch entries in the request have the same
Id
.HTTP Status Code: 400
- BatchRequestTooLong
-
The length of all the messages put together is more than the limit.
HTTP Status Code: 400
- EmptyBatchRequest
-
The batch request doesn't contain any entries.
HTTP Status Code: 400
- InvalidBatchEntryId
-
The
Id
of a batch entry in a batch request doesn't abide by the specification.HTTP Status Code: 400
- InvalidSecurity
-
When the request to a queue is not HTTPS and SigV4.
HTTP Status Code: 400
- KmsAccessDenied
-
The caller doesn't have the required KMS access.
HTTP Status Code: 400
- KmsDisabled
-
The request was denied due to request throttling.
HTTP Status Code: 400
- KmsInvalidKeyUsage
-
The request was rejected for one of the following reasons:
-
The KeyUsage value of the KMS key is incompatible with the API operation.
-
The encryption algorithm or signing algorithm specified for the operation is incompatible with the type of key material in the KMS key (KeySpec).
HTTP Status Code: 400
-
- KmsInvalidState
-
The request was rejected because the state of the specified resource is not valid for this request.
HTTP Status Code: 400
- KmsNotFound
-
The request was rejected because the specified entity or resource could not be found.
HTTP Status Code: 400
- KmsOptInRequired
-
The request was rejected because the specified key policy isn't syntactically or semantically correct.
HTTP Status Code: 400
- KmsThrottled
-
AWS KMS throttles requests for the following conditions.
HTTP Status Code: 400
- QueueDoesNotExist
-
The specified queue doesn't exist.
HTTP Status Code: 400
- RequestThrottled
-
The request was denied due to request throttling.
-
The rate of requests per second exceeds the AWS KMS request quota for an account and Region.
-
A burst or sustained high rate of requests to change the state of the same KMS key. This condition is often known as a "hot key."
-
Requests for operations on KMS keys in a AWS CloudHSM key store might be throttled at a lower-than-expected rate when the AWS CloudHSM cluster associated with the AWS CloudHSM key store is processing numerous commands, including those unrelated to the AWS CloudHSM key store.
HTTP Status Code: 400
-
- TooManyEntriesInBatchRequest
-
The batch request contains more entries than permissible.
HTTP Status Code: 400
- UnsupportedOperation
-
Error code 400. Unsupported operation.
HTTP Status Code: 400
Examples
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. The structure of AUTHPARAMS
depends on the signature of the API request.
For more information, see
Examples of Signed Signature Version 4 Requests in the
AWS General Reference.
Example
Using AWS query protocol
Sample Request
POST /177715257436/MyQueue/ HTTP/1.1
Host: sqs.us-east-1.amazonaws.com
X-Amz-Date: <Date>
Content-Type: application/x-www-form-urlencoded
Authorization: <AuthParams>
Content-Length: <PayloadSizeBytes>
Connection: Keep-Alive
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
Sample Response
HTTP/1.1 200 OK
<?xml version="1.0"?>
<SendMessageBatchResponse xmlns="http://queue.amazonaws.com/doc/2012-11-05/">
<SendMessageBatchResult>
<SendMessageBatchResultEntry>
<Id>test_msg_001</Id>
<MessageId>60e827c3-c8a5-410a-af0e-fb43746e70b1</MessageId>
<MD5OfMessageBody>0e024d309850c78cba5eabbeff7cae71</MD5OfMessageBody>
</SendMessageBatchResultEntry>
<SendMessageBatchResultEntry>
<Id>test_msg_00</Id>
<MessageId>c6e7fc6a-b802-4724-be06-59833004578b</MessageId>
<MD5OfMessageBody>7fb8146a82f95e0af155278f406862c2</MD5OfMessageBody>
<MD5OfMessageAttributes>ba056227cfd9533dba1f72ad9816d233</MD5OfMessageAttributes>
</SendMessageBatchResultEntry>
</SendMessageBatchResult>
<ResponseMetadata>
<RequestId>5150a701-14f7-5609-b136-fb71a0ca744a</RequestId>
</ResponseMetadata>
</SendMessageBatchResponse>
Example
Using AWS query protocol
Sample Request
POST /177715257436/MyQueue/ HTTP/1.1
Host: sqs.us-east-1.amazonaws.com
X-Amz-Date: <Date>
Content-Type: application/x-www-form-urlencoded
Authorization: <AuthParams>
Content-Length: <PayloadSizeBytes>
Connection: Keep-Alive
Action=SendMessageBatch
&SendMessageBatchRequestEntry.1.Id=test_msg_no_message_timer
&SendMessageBatchRequestEntry.1.MessageBody=test%20message%20body%201
&SendMessageBatchRequestEntry.2.Id=test_msg_delay_45_seconds
&SendMessageBatchRequestEntry.2.MessageBody=test%20message%20body%202
&SendMessageBatchRequestEntry.2.DelaySeconds=45
&SendMessageBatchRequestEntry.3.Id=test_msg_delay_2_minutes
&SendMessageBatchRequestEntry.3.MessageBody=test%20message%20body%203
&SendMessageBatchRequestEntry.3.DelaySeconds=120
See Also
For more information about using this API in one of the language-specific AWS SDKs, see the following: