Skip to content

SNSClient.publish

rboto-sns==0.4.0 · Service index · Types

Model summary (excerpt): Sends a message to an Amazon SNS topic, a text message (SMS message) directly to a phone number, or a message to a mobile platform endpoint (when you specify the TargetArn ). If you send a message to a topic, Amazon SNS delivers the message to each endpoint that is subscribed to the topic. The format of the message depends on the notification protocol for each subscribed endpoint. When a...

Install and imports

python -m pip install "rboto[sns]==0.4.0"
from rboto import SNSClient
from rboto_sns.types import (
    MessageAttributeValue,
    PublishOutput,
)

Signature

async def publish(
    *,
    message: str,
    topic_arn: str | None = None,
    target_arn: str | None = None,
    phone_number: str | None = None,
    subject: str | None = None,
    message_structure: str | None = None,
    message_attributes: dict[str, MessageAttributeValue] | None = None,
    message_deduplication_id: str | None = None,
    message_group_id: str | None = None,
) -> PublishOutput: ...

Arguments without defaults are required. None omits an optional request argument. Static types do not validate resource existence, permissions, lengths, ranges, or conditional service requirements.

Arguments

Argument Required Model notes (excerpt)
message Yes The message you want to send. If you are publishing to a topic and you want to send the same message to all transport protocols, include the text of the message as a String value. If you want to send different messages for each transport protocol, set the value of the MessageStructure parameter to json and use a JSON object for the Message parameter. Constraints: With the exception of SMS,...
topic_arn No The topic you want to publish to. If you don't specify a value for the TopicArn parameter, you must specify a value for the PhoneNumber or TargetArn parameters.
target_arn No If you don't specify a value for the TargetArn parameter, you must specify a value for the PhoneNumber or TopicArn parameters.
phone_number No The phone number to which you want to deliver an SMS message. Use E.164 format. If you don't specify a value for the PhoneNumber parameter, you must specify a value for the TargetArn or TopicArn parameters.
subject No Optional parameter to be used as the "Subject" line when the message is delivered to email endpoints. This field will also be included, if present, in the standard JSON messages delivered to other endpoints. Constraints: Subjects must be UTF-8 text with no line breaks or control characters, and less than 100 characters long.
message_structure No Set MessageStructure to json if you want to send a different message for each protocol. For example, using one publish action, you can send a short message to your SMS subscribers and a longer message to your email subscribers. If you set MessageStructure to json , the value of the Message parameter must: be a syntactically valid JSON object; and contain at least a top-level JSON key of...
message_attributes No Message attributes for Publish action.
message_deduplication_id No This parameter applies only to FIFO (first-in-first-out) topics. The MessageDeduplicationId can contain up to 128 alphanumeric characters (a-z, A-Z, 0-9) and punctuation (!"#$%&'()*+,-./:; < =>?@[\]^_`{|}~) . Every message must have a unique MessageDeduplicationId , which is a token used for deduplication of sent messages within the 5 minute minimum deduplication interval. The scope of...
message_group_id No The MessageGroupId can contain up to 128 alphanumeric characters (a-z, A-Z, 0-9) and punctuation (!"#$%&'()*+,-./:; < =>?@[\]^_`{|}~) . For FIFO topics: The MessageGroupId is a tag that specifies that a message belongs to a specific message group. Messages that belong to the same message group are processed in a FIFO manner (however, messages in different message groups might be processed out...

Output

PublishOutput.

Read-only native attributes, accessed as response.field. Collection getters materialize Python values; to_dict() recursively materializes a mapping. Streams are consumed once.

Field Type Presence References
message_id str | None Always present —
sequence_number str | None Always present —

| None means a value can be absent. Output mappings include every declared key; optional input keys may be omitted. Unknown output enum/union variants are not automatically valid inputs.

MessageAttributeValue, PublishOutput

Follow these links for nested inputs and outputs; recursive types link back to the same type page.

Pagination and streaming

No generated paginator for this operation.

No output stream.

Errors

Import from rboto_sns.exceptions:

AuthorizationError, EndpointDisabledError, InternalError, InvalidParameterError, InvalidParameterValueError, InvalidSecurityError, KMSAccessDeniedError, KMSDisabledError, KMSInvalidStateError, KMSNotFoundError, KMSOptInRequiredError, KMSThrottlingError, NotFoundError, PlatformApplicationDisabledError, ValidationError.

Other service failures use the service base error; credential, transport and timeout failures use shared errors.

Example

Complete, type-checked service example. Replace its placeholders and configure credentials before running it.

import asyncio

from rboto import SNSClient


async def main() -> None:
    client = SNSClient(region="us-east-1")
    response = await client.publish(
        topic_arn="arn:aws:sns:us-east-1:123456789012:notifications",
        message="Your report is ready",
    )
    print(response.message_id)


if __name__ == "__main__":
    asyncio.run(main())

Service guide · Pinned model