subscribe ( $topic_arn, $protocol, $endpoint, $opt )

The Subscribe action prepares to subscribe an endpoint by sending the endpoint a confirmation message. To actually create a subscription, the endpoint owner must call the ConfirmSubscription action with the token from the confirmation message. Confirmation tokens are valid for three days.

Access

public

Parameters

Parameter

Type

Required

Description

$topic_arn

string

Required

The ARN of topic you want to subscribe to.

$protocol

string

Required

The protocol you want to use. Supported protocols include:

  • http — delivery of JSON-encoded message via HTTP POST
  • https — delivery of JSON-encoded message via HTTPS POST
  • email — delivery of message via SMTP
  • email-json — delivery of JSON-encoded message via SMTP
  • sqs — delivery of JSON-encoded message to an Amazon SQS queue

$endpoint

string

Required

The endpoint that you want to receive notifications. Endpoints vary by protocol:

  • For the http protocol, the endpoint is an URL beginning with “http://”
  • For the https protocol, the endpoint is a URL beginning with “https://”
  • For the email protocol, the endpoint is an e-mail address
  • For the email-json protocol, the endpoint is an e-mail address
  • For the sqs protocol, the endpoint is the ARN of an Amazon SQS queue

$opt

array

Optional

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

  • 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

Subscribe to a topic.

$sns = new AmazonSNS();

// Subscribe to notifications

$response = $sns->subscribe(
	'arn:aws:sns:us-east-1:9876543210:my-topic',
	'sqs',
	'arn:aws:sqs:us-east-1:9876543210:my-sqs-queue'
);

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

Related Methods

Source

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

public function subscribe($topic_arn, $protocol, $endpoint, $opt = null)
{
    if (!$opt) $opt = array();
    $opt['TopicArn'] = $topic_arn;
    $opt['Protocol'] = $protocol;
    $opt['Endpoint'] = $endpoint;
    
    return $this->authenticate('Subscribe', $opt);
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback