Skip to content

publish_batch

publish_batch(
    topic_arn: topicARN,
    publish_batch_request_entries: PublishBatchRequestEntryList,
    *,
    config_overrides: Optional[SNSClientConfig] = None,
) -> PublishBatchResponse

Publishes up to 10 messages to the specified topic in a single batch. This is a batch version of the Publish API. If you try to send more than 10 messages in a single batch request, you will receive a TooManyEntriesInBatchRequest exception.

For FIFO topics, multiple messages within a single batch are published in the order they are sent, and messages are deduplicated within the batch and across batches for five minutes.

The result of publishing 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.

By default, 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). To publish larger batches, set the topic's MaximumMessageSize attribute, which supports values up to 1 MiB (1,048,576 bytes). The combined size of all messages in the batch, including each message's body and attributes, must not exceed the topic's MaximumMessageSize.

For more information, see Large message payloads in the Amazon SNS Developer Guide.

The PublishBatch API can send up to 10 messages at a time. If you attempt to send more than 10 messages in one request, you will encounter a TooManyEntriesInBatchRequest exception. In such cases, split your messages into multiple requests, each containing no more than 10 messages.

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:

&AttributeName.1=first

&AttributeName.2=second

If you send a batch message to a topic, Amazon SNS publishes the batch message to each endpoint that is subscribed to the topic. The format of the batch message depends on the notification protocol for each subscribed endpoint.

When a messageId is returned, the batch message is saved, and Amazon SNS immediately delivers the message to subscribers.

Parameters:

  • topic_arn (topicARN) –

    The Amazon resource name (ARN) of the topic you want to batch publish to.

  • publish_batch_request_entries (PublishBatchRequestEntryList) –

    A list of PublishBatch request entries to be sent to the SNS topic.

Raises:

Source code in docs_src/capo_sns/_services/sns.py
def publish_batch(
    self,
    topic_arn: "capo_sns.types.topic_arn.topicARN",
    publish_batch_request_entries: "capo_sns.types.publish_batch_request_entry_list.PublishBatchRequestEntryList",
    *,
    config_overrides: Optional[SNSClientConfig] = None,
) -> "capo_sns.types.publish_batch_response.PublishBatchResponse":
    """<p>Publishes up to 10 messages to the specified topic in a single batch. This is a batch version of the <code>Publish</code> API. If you try to send more than 10 messages in a single batch request, you will receive a <code>TooManyEntriesInBatchRequest</code> exception.</p> <p>For FIFO topics, multiple messages within a single batch are published in the order they are sent, and messages are deduplicated within the batch and across batches for five minutes.</p> <p>The result of publishing 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.</p> <p>By default, 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). To publish larger batches, set the topic's <code>MaximumMessageSize</code> attribute, which supports values up to 1 MiB (1,048,576 bytes). The combined size of all messages in the batch, including each message's body and attributes, must not exceed the topic's <code>MaximumMessageSize</code>.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/sns/latest/dg/large-message-payloads.html">Large message payloads</a> in the <i>Amazon SNS Developer Guide.</i> </p> <important> <p>The <code>PublishBatch</code> API can send up to 10 messages at a time. If you attempt to send more than 10 messages in one request, you will encounter a <code>TooManyEntriesInBatchRequest</code> exception. In such cases, split your messages into multiple requests, each containing no more than 10 messages.</p> </important> <p>Some actions take lists of parameters. These lists are specified using the <code>param.n</code> notation. Values of <code>n</code> are integers starting from <b>1</b>. For example, a parameter list with two elements looks like this:</p> <p> <code>&AttributeName.1=first</code> </p> <p> <code>&AttributeName.2=second</code> </p> <p>If you send a batch message to a topic, Amazon SNS publishes the batch message to each endpoint that is subscribed to the topic. The format of the batch message depends on the notification protocol for each subscribed endpoint.</p> <p>When a <code>messageId</code> is returned, the batch message is saved, and Amazon SNS immediately delivers the message to subscribers.</p>

    Args:
        topic_arn: <p>The Amazon resource name (ARN) of the topic you want to batch publish to.</p>
        publish_batch_request_entries: <p>A list of <code>PublishBatch</code> request entries to be sent to the SNS topic.</p>

    Raises:
        capo_sns.errors.authorization_error_exception.AuthorizationErrorException: <p>Indicates that the user has been denied access to the requested resource.</p>
        capo_sns.errors.batch_entry_ids_not_distinct_exception.BatchEntryIdsNotDistinctException: <p>Two or more batch entries in the request have the same <code>Id</code>.</p>
        capo_sns.errors.batch_request_too_long_exception.BatchRequestTooLongException: <p>The length of all the batch messages put together is more than the limit.</p>
        capo_sns.errors.empty_batch_request_exception.EmptyBatchRequestException: <p>The batch request doesn't contain any entries.</p>
        capo_sns.errors.endpoint_disabled_exception.EndpointDisabledException: <p>Exception error indicating endpoint disabled.</p>
        capo_sns.errors.internal_error_exception.InternalErrorException: <p>Indicates an internal service error.</p>
        capo_sns.errors.invalid_batch_entry_id_exception.InvalidBatchEntryIdException: <p>The <code>Id</code> of a batch entry in a batch request doesn't abide by the specification. </p>
        capo_sns.errors.invalid_parameter_exception.InvalidParameterException: <p>Indicates that a request parameter does not comply with the associated constraints.</p>
        capo_sns.errors.invalid_parameter_value_exception.InvalidParameterValueException: <p>Indicates that a request parameter does not comply with the associated constraints.</p>
        capo_sns.errors.invalid_security_exception.InvalidSecurityException: <p>The credential signature isn't valid. You must use an HTTPS endpoint and sign your request using Signature Version 4.</p>
        capo_sns.errors.kms_access_denied_exception.KMSAccessDeniedException: <p>The ciphertext references a key that doesn't exist or that you don't have access to.</p>
        capo_sns.errors.kms_disabled_exception.KMSDisabledException: <p>The request was rejected because the specified Amazon Web Services KMS key isn't enabled.</p>
        capo_sns.errors.kms_invalid_state_exception.KMSInvalidStateException: <p>The request was rejected because the state of the specified resource isn't valid for this request. For more information, see <a href="https://docs.aws.amazon.com/kms/latest/developerguide/key-state.html">Key states of Amazon Web Services KMS keys</a> in the <i>Key Management Service Developer Guide</i>.</p>
        capo_sns.errors.kms_not_found_exception.KMSNotFoundException: <p>The request was rejected because the specified entity or resource can't be found.</p>
        capo_sns.errors.kms_opt_in_required.KMSOptInRequired: <p>The Amazon Web Services access key ID needs a subscription for the service.</p>
        capo_sns.errors.kms_throttling_exception.KMSThrottlingException: <p>The request was denied due to request throttling. For more information about throttling, see <a href="https://docs.aws.amazon.com/kms/latest/developerguide/limits.html#requests-per-second">Limits</a> in the <i>Key Management Service Developer Guide.</i> </p>
        capo_sns.errors.not_found_exception.NotFoundException: <p>Indicates that the requested resource does not exist.</p>
        capo_sns.errors.platform_application_disabled_exception.PlatformApplicationDisabledException: <p>Exception error indicating platform application disabled.</p>
        capo_sns.errors.too_many_entries_in_batch_request_exception.TooManyEntriesInBatchRequestException: <p> The batch request contains more entries than permissible (more than 10).</p>
        capo_sns.errors.validation_exception.ValidationException: <p>Indicates that a parameter in the request is invalid.</p>
        capo_sns.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_sns.types.publish_batch_input.PublishBatchInput]",
    ) -> OperationResponse[
        "capo_sns.types.publish_batch_response.PublishBatchResponse"
    ]:
        import capo_sns._operations.amazon_simple_notification_service.publish_batch

        output, http_response = (
            capo_sns._operations.amazon_simple_notification_service.publish_batch.publish_batch(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("PublishBatch")
    )
    input_: capo_sns.types.publish_batch_input.PublishBatchInput = {
        "topic_arn": topic_arn,
        "publish_batch_request_entries": publish_batch_request_entries,
    }

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output