publish ( $topic_arn, $message, $opt )

The Publish action sends a message to all of a topic’s subscribed endpoints. When a messageId is returned, the message has been saved and Amazon SNS will attempt to deliver it to the topic’s subscribers shortly. The format of the outgoing message to each subscribed endpoint depends on the notification protocol selected.

Access

public

Parameters

Parameter

Type

Required

Description

$topic_arn

string

Required

The topic you want to publish to.

$message

string

Required

The message you want to send to the topic. Constraints: Messages must be UTF-8 encoded strings at most 8 KB in size (8192 bytes, not 8192 characters).

$opt

array

Optional

An associative array of parameters that can have the following keys:

  • Subject - string - Optional - Optional parameter to be used as the “Subject” line of when the message is delivered to e-mail endpoints. This field will also be included, if present, in the standard JSON messages delivered to other endpoints. Constraints: Subjects must be ASCII text that begins with a letter, number or punctuation mark; must not include line breaks or control characters; and must be less than 100 characters long.
  • MessageStructure - string - Optional - Optional parameter. It will have one valid value: “json”. If this option, Message is present and set to “json”, the value of Message must: be a syntactically valid JSON object. It must contain at least a top level JSON key of “default” with a value that is a string. For any other top level key that matches one of our transport protocols (e.g. “http”), then the corresponding value (if it is a string) will be used for the message published for that protocol Constraints: Keys in the JSON object that correspond to supported transport protocols must have simple JSON string values. The values will be parsed (unescaped) before they are used in outgoing messages. Typically, outbound notifications are JSON encoded (meaning, the characters will be reescaped for sending). JSON strings are UTF-8. Values have a minimum length of 0 (the empty string, “”, is allowed). Values have a maximum length bounded by the overall message size (so, including multiple protocols may limit message sizes). Non-string values will cause the key to be ignored. Keys that do not correspond to supported transport protocols will be ignored. Duplicate keys are not allowed. Failure to parse or validate any key or value in the message will cause the Publish call to return an error (no partial delivery).
  • curlopts - array - Optional - A set of values to pass directly into curl_setopt(), where the key is a pre-defined CURLOPT_* constant.
  • returnCurlHandle - boolean - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.

Returns

Type

Description

CFResponse

A CFResponse object containing a parsed HTTP response.

Examples

Publish a message to the topic.

$sns = new AmazonSNS();

// Get topic attributes
$response = $sns->publish(
	'arn:aws:sns:us-east-1:9876543210:example-topic',
	'This is my very first message to the world!',
	array(
		'Subject' => 'Hello world!'
	)
);

// Success?
var_dump($response->isOK());
Result:
bool(true)

Related Methods

Source

Method defined in services/sns.class.php | Toggle source view (8 lines) | View on GitHub

public function publish($topic_arn, $message, $opt = null)
{
    if (!$opt) $opt = array();
    $opt['TopicArn'] = $topic_arn;
    $opt['Message'] = $message;
    
    return $this->authenticate('Publish', $opt);
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback