create_bucket_notification ( $bucket, $topic_arn, $event, $opt )

Enables notifications of specified events for an Amazon S3 bucket. Currently, the s3:ReducedRedundancyLostObject event is the only event supported for notifications. The s3:ReducedRedundancyLostObject event is triggered when Amazon S3 detects that it has lost all copies of an Amazon S3 object and can no longer service requests for that object.

If the bucket owner and Amazon SNS topic owner are the same, the bucket owner has permission to publish notifications to the topic by default. Otherwise, the owner of the topic must create a policy to enable the bucket owner to publish to the topic.

By default, only the bucket owner can configure notifications on a bucket. However, bucket owners can use bucket policies to grant permission to other users to set this configuration with the s3:PutBucketNotification permission.

After a PUT operation is called to configure notifications on a bucket, Amazon S3 publishes a test notification to ensure that the topic exists and that the bucket owner has permission to publish to the specified topic. If the notification is successfully published to the SNS topic, the PUT operation updates the bucket configuration and returns the 200 OK responses with a x-amz-sns-test-message-id header containing the message ID of the test notification sent to topic.

Access

public

Parameters

Parameter

Type

Required

Description

$bucket

string

Required

The name of the bucket to create bucket notifications for.

$topic_arn

string

Required

The SNS topic ARN to send notifications to.

$event

string

Required

The event type to listen for.

$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

Create bucket notification.

// Instantiate the class
$s3 = new AmazonS3();
$bucket = 'my-bucket' . strtolower($s3->key);

// Create an SNS topic
$sns = new AmazonSNS();
$topic = $sns->create_topic('my-topic')->body->TopicArn()->first();

$response = $s3->create_bucket_notification($bucket, $topic, 's3:ReducedRedundancyLostObject');

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

Related Methods

See Also

Source

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

public function create_bucket_notification($bucket, $topic_arn, $event, $opt = null)
{
    if (!$opt) $opt = array();
    $opt['verb'] = 'PUT';
    $opt['sub_resource'] = 'notification';
    $opt['headers'] = array(
        'Content-Type' => 'application/xml'
    );

    $xml = simplexml_load_string($this->base_notification_xml);
    $topic_config = $xml->addChild('TopicConfiguration');
    $topic_config->addChild('Topic', $topic_arn);
    $topic_config->addChild('Event', $event);

    $opt['body'] = $xml->asXML();

    // Authenticate to S3
    return $this->authenticate($bucket, $opt);
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback