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 1 MiB 1,048,576 bytes.
A message can include only XML, JSON, and unformatted text. The following Unicode characters are allowed. For more information, see the W3C specification for characters.
#x9 | #xA | #xD | #x20 to #xD7FF | #xE000 to #xFFFD | #x10000 to #x10FFFF
If a message contains characters outside the allowed set, Amazon SQS rejects the message and returns an InvalidMessageContents error. Ensure that your message body includes only valid characters to avoid this exception.
If you don't specify the DelaySeconds parameter for an entry, Amazon SQS uses the default value for the queue.
Parameters:
Raises:
-
BatchEntryIdsNotDistinct
–
Two or more batch entries in the request have the same Id.
-
BatchRequestTooLong
–
The length of all the messages put together is more than the limit.
-
EmptyBatchRequest
–
The batch request doesn't contain any entries.
-
InvalidAddress
–
The specified ID is invalid.
-
InvalidBatchEntryId
–
The Id of a batch entry in a batch request doesn't abide by the specification.
-
InvalidSecurity
–
The request was not made over HTTPS or did not use SigV4 for signing.
-
KmsAccessDenied
–
The caller doesn't have the required KMS access.
-
KmsDisabled
–
The request was denied due to request throttling.
-
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).
-
KmsInvalidState
–
The request was rejected because the state of the specified resource is not valid for this request.
-
KmsNotFound
–
The request was rejected because the specified entity or resource could not be found.
-
KmsOptInRequired
–
The request was rejected because the specified key policy isn't syntactically or semantically correct.
-
KmsThrottled
–
Amazon Web Services KMS throttles requests for the following conditions.
-
QueueDoesNotExist
–
Ensure that the QueueUrl is correct and that the queue has not been deleted.
-
RequestThrottled
–
The request was denied due to request throttling.
-
Exceeds the permitted request rate for the queue or for the recipient of the request.
-
Ensure that the request rate is within the Amazon SQS limits for sending messages. For more information, see Amazon SQS quotas in the Amazon SQS Developer Guide.
-
TooManyEntriesInBatchRequest
–
-
UnsupportedOperation
–
Error code 400. Unsupported operation.
-
UnknownServiceError
–
The service returned an error code this client does not model.
Source code in docs_src/capo_sqs/_services/sqs.py
| def send_message_batch(
self,
queue_url: "capo_sqs.types.string.String",
entries: "capo_sqs.types.send_message_batch_request_entry_list.SendMessageBatchRequestEntryList",
*,
config_overrides: Optional[SQSClientConfig] = None,
) -> "capo_sqs.types.send_message_batch_result.SendMessageBatchResult":
"""<p>You can use <code>SendMessageBatch</code> 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 <code> <a>SendMessage</a>.</code> For a FIFO queue, multiple messages within a single batch are enqueued in the order they are sent.</p> <p>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 <code>200</code>.</p> <p>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 1 MiB 1,048,576 bytes.</p> <important> <p>A message can include only XML, JSON, and unformatted text. The following Unicode characters are allowed. For more information, see the <a href="http://www.w3.org/TR/REC-xml/#charsets">W3C specification for characters</a>.</p> <p> <code>#x9</code> | <code>#xA</code> | <code>#xD</code> | <code>#x20</code> to <code>#xD7FF</code> | <code>#xE000</code> to <code>#xFFFD</code> | <code>#x10000</code> to <code>#x10FFFF</code> </p> <p>If a message contains characters outside the allowed set, Amazon SQS rejects the message and returns an InvalidMessageContents error. Ensure that your message body includes only valid characters to avoid this exception.</p> </important> <p>If you don't specify the <code>DelaySeconds</code> parameter for an entry, Amazon SQS uses the default value for the queue.</p>
Args:
queue_url: <p>The URL of the Amazon SQS queue to which batched messages are sent.</p> <p>Queue URLs and names are case-sensitive.</p>
entries: <p>A list of <code> <a>SendMessageBatchRequestEntry</a> </code> items.</p>
Raises:
capo_sqs.errors.batch_entry_ids_not_distinct.BatchEntryIdsNotDistinct: <p>Two or more batch entries in the request have the same <code>Id</code>.</p>
capo_sqs.errors.batch_request_too_long.BatchRequestTooLong: <p>The length of all the messages put together is more than the limit.</p>
capo_sqs.errors.empty_batch_request.EmptyBatchRequest: <p>The batch request doesn't contain any entries.</p>
capo_sqs.errors.invalid_address.InvalidAddress: <p>The specified ID is invalid.</p>
capo_sqs.errors.invalid_batch_entry_id.InvalidBatchEntryId: <p>The <code>Id</code> of a batch entry in a batch request doesn't abide by the specification.</p>
capo_sqs.errors.invalid_security.InvalidSecurity: <p>The request was not made over HTTPS or did not use SigV4 for signing.</p>
capo_sqs.errors.kms_access_denied.KmsAccessDenied: <p>The caller doesn't have the required KMS access.</p>
capo_sqs.errors.kms_disabled.KmsDisabled: <p>The request was denied due to request throttling.</p>
capo_sqs.errors.kms_invalid_key_usage.KmsInvalidKeyUsage: <p>The request was rejected for one of the following reasons:</p> <ul> <li> <p>The KeyUsage value of the KMS key is incompatible with the API operation.</p> </li> <li> <p>The encryption algorithm or signing algorithm specified for the operation is incompatible with the type of key material in the KMS key (KeySpec).</p> </li> </ul>
capo_sqs.errors.kms_invalid_state.KmsInvalidState: <p>The request was rejected because the state of the specified resource is not valid for this request.</p>
capo_sqs.errors.kms_not_found.KmsNotFound: <p>The request was rejected because the specified entity or resource could not be found. </p>
capo_sqs.errors.kms_opt_in_required.KmsOptInRequired: <p>The request was rejected because the specified key policy isn't syntactically or semantically correct.</p>
capo_sqs.errors.kms_throttled.KmsThrottled: <p>Amazon Web Services KMS throttles requests for the following conditions.</p>
capo_sqs.errors.queue_does_not_exist.QueueDoesNotExist: <p>Ensure that the <code>QueueUrl</code> is correct and that the queue has not been deleted.</p>
capo_sqs.errors.request_throttled.RequestThrottled: <p>The request was denied due to request throttling.</p> <ul> <li> <p>Exceeds the permitted request rate for the queue or for the recipient of the request.</p> </li> <li> <p>Ensure that the request rate is within the Amazon SQS limits for sending messages. For more information, see <a href="https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-quotas.html#quotas-requests">Amazon SQS quotas</a> in the <i>Amazon SQS Developer Guide</i>.</p> </li> </ul>
capo_sqs.errors.too_many_entries_in_batch_request.TooManyEntriesInBatchRequest: <p>The batch request contains more entries than permissible. For Amazon SQS, the maximum number of entries you can include in a single <a href="https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_SendMessageBatch.html">SendMessageBatch</a>, <a href="https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_DeleteMessageBatch.html">DeleteMessageBatch</a>, or <a href="https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_ChangeMessageVisibilityBatch.html">ChangeMessageVisibilityBatch</a> request is 10.</p>
capo_sqs.errors.unsupported_operation.UnsupportedOperation: <p>Error code 400. Unsupported operation.</p>
capo_sqs.errors.UnknownServiceError: The service returned an error code this client does not model.
"""
def _handler(
req: "OperationRequest[capo_sqs.types.send_message_batch_request.SendMessageBatchRequest]",
) -> OperationResponse[
"capo_sqs.types.send_message_batch_result.SendMessageBatchResult"
]:
import capo_sqs._operations.amazon_sqs.send_message_batch
output, http_response = (
capo_sqs._operations.amazon_sqs.send_message_batch.send_message_batch(
req.options, req.input
)
)
return OperationResponse(output=output, response=http_response)
interceptors_, options_ = self.operation_options(
config_overrides, OperationLogging("SendMessageBatch")
)
input_: capo_sqs.types.send_message_batch_request.SendMessageBatchRequest = {
"queue_url": queue_url,
"entries": entries,
}
response = execute_pipeline(
OperationRequest(input=input_, options=options_),
handler=_handler,
interceptors=list(interceptors_),
)
response.response.close()
return response.output
|