PUT Bucket notification
Description
The Amazon S3 notification feature enables you to receive notifications when certain events happen in your bucket. For more information about event notifications, go to Configuring Event Notifications in the Amazon Simple Storage Service Developer Guide.
Using this API, you can replace an existing notification configuration. The configuration is an XML file that defines the event types that you want Amazon S3 to publish and the destination where you want Amazon S3 to publish an event notification when it detects an event of the specified type.
By default, your bucket has no event notifications configured. That is, the
notification configuration will be an empty
NotificationConfiguration
.
<NotificationConfiguration> </NotificationConfiguration>
This operation replaces the existing notification configuration with the configuration you include in the request body.
After Amazon S3 receives this request, it first verifies that any Amazon Simple Notification Service (Amazon SNS) or Amazon Simple Queue Service (Amazon SQS) destination exists, and that the bucket owner has permission to publish to it by sending a test notification. In the case of AWS Lambda destinations, Amazon S3 verifies that the Lambda function permissions grant Amazon S3 permission to invoke the function from the Amazon S3 bucket. For more information, go to Configuring Notifications for Amazon S3 Events in the Amazon Simple Storage Service Developer Guide.
You can disable notifications by adding the empty NotificationConfiguration
element.
By default, only the bucket owner can configure notifications on a bucket. However,
bucket
owners can use a bucket policy to grant permission to other users to set this
configuration with s3:PutBucketNotification
permission.
Note
The PUT notification is an atomic operation. For example, suppose your notification configuration includes SNS topic, SQS queue, and Lambda function configurations. When you send a PUT request with this configuration, Amazon S3 sends test messages to your SNS topic. If the message fails, the entire PUT operation will fail, and Amazon S3 will not add the configuration to your bucket.
Requests
Syntax
PUT /?notification HTTP/1.1 Host:
bucketname
.s3.amazonaws.com Date:date
Authorization:authorization string
(see Authenticating Requests (AWS Signature Version 4)) <NotificationConfiguration> <TopicConfiguration> <Id>ConfigurationId
</Id> <Filter> <S3Key> <FilterRule> <Name>prefix</Name> <Value>prefix-value
</Value> </FilterRule> <FilterRule> <Name>suffix</Name> <Value>suffix-value
</Value> </FilterRule> </S3Key> </Filter> <Topic>TopicARN
</Topic> <Event>event-type
</Event> <Event>event-type
</Event> ... </TopicConfiguration> <QueueConfiguration> <Id>ConfigurationId
</Id> <Filter> ... </Filter> <Queue>QueueARN
</Queue> <Event>event-type
</Event> <Event>event-type
</Event> ... </QueueConfiguration> ... <CloudFunctionConfiguration> <Id>ConfigurationId
</Id> <Filter> ... </Filter> <CloudFunction>cloud-function-arn
</CloudFunction> <Event>event-type
</Event> ... </CloudFunctionConfiguration> ... </NotificationConfiguration>
Request Parameters
This implementation of the operation does not use request parameters.
Request Headers
This implementation of the operation uses only request headers that are common to all operations. For more information, see Common Request Headers.
Request Elements
Name | Description | Required |
---|---|---|
CloudFunction
|
Lambda cloud function ARN that Amazon S3 can invoke when it detects events of the specified type. Type: String Ancestor:
|
Required if CloudFunctionConfiguration is
added.
|
CloudFunctionConfiguration
|
Container for specifying the AWS Lambda notification configuration. Type: Container Children: An Ancestor:
|
No |
Event
|
Bucket event for which to send notifications. Note You can add multiple instance of
Type: String Valid Values: For a list of supported event types, go to Configuring Event Notifications in the Amazon Simple Storage Service Developer Guide. Ancestor: |
Required if TopicConfiguration ,
QueueConfiguration or
CloudFunctionConfiguration is
added.
|
Filter
|
Container for Type: Container Children: Ancestor: |
No |
FilterRule
|
Container for key value pair that defines the criteria for the filter rule. Container Type: Container Children: Ancestor: |
No |
Id
|
Optional unique identifier for each of the configurations
in the Type: String Ancestor: |
No |
Name
|
Object key name prefix or suffix identifying one or more objects to which the filtering rule applies. Maximum prefix length can be up to 1,024 characters. Overlapping prefixes and suffixes are not supported. For more information, go to Configuring Event Notifications in the Amazon Simple Storage Service Developer Guide. Type: String Ancestor: Valid values: |
No |
NotificationConfiguration
|
Container for specifying the notification configuration of the bucket. If this element is empty, notifications are turned off on the bucket. Type: Container Children: one or more
Ancestor: None |
Yes |
Queue
|
Amazon SQS queue ARN to which Amazon S3 will publish a message when it detects events of specified type. Type: String Ancestor:
|
Required if QueueConfiguration is added.
|
QueueConfiguration
|
Container for specifying the SQS queue configuration for the notification. You can add one or more of these queue configurations, each identifying one or more event types. Type: Container Children: An Ancestor:
|
No |
S3Key
|
Container for object key name prefix and suffix filtering rules. Type: Container Children: One or more Ancestor: |
No |
Topic
|
Amazon SNS topic ARN to which Amazon S3 will publish a message when it detects events of specified type. Type: String Ancestor:
|
Required if |
TopicConfiguration
|
Container for specifying an SNS topic configuration for the notification. Type: Container Children: An Ancestor:
|
No |
Value
|
Specifies the object key name prefix or suffix to filter on. Type: String Ancestor: |
No |
Responses
Response Headers
In addition to the common response headers (see Common Response Headers), if the configuration in the request body includes only one
TopicConfiguration
specifying only the
s3:ReducedRedundancyLostObject event type, the response
will also include the x-amz-sns-test-message-id header
containing the message ID of the test notification sent to topic.
This implementation of the operation uses only response headers that are common to most responses. For more information, see Common Response Headers.
Response Elements
This implementation of the operation does not return response elements.
Special Errors
Amazon S3 checks the validity of the proposed NotificationConfiguration
element and verifies whether the proposed configuration is valid when you call
the
PUT
operation. The following table lists the errors and
possible causes.
HTTP Error | Code | Cause |
---|---|---|
HTTP 400 Bad Request |
InvalidArgument |
The following conditions can cause this error:
|
HTTP 403 Forbidden |
AccessDenied |
You are not the owner of the specified bucket, or you do
not have the |
For general information about Amazon S3 errors and a list of error codes, see Error Responses.
Examples
Example 1: Configure Notification to Invoke a cloud function in Lambda
The following notification configuration includes
CloudFunctionConfiguration
, which identifies the event
type for which Amazon S3 can invoke a cloud function and the name of the cloud
function
to invoke.
<NotificationConfiguration> <CloudFunctionConfiguration> <Id>ObjectCreatedEvents</Id> <CloudFunction>arn:aws:lambda:us-west-2:35667example:function:CreateThumbnail</CloudFunction> <Event>s3:ObjectCreated:*</Event> </CloudFunctionConfiguration> </NotificationConfiguration>
The following PUT uploads the notification configuration. The operation replaces the existing notification configuration.
PUT http://s3.amazonaws.com/examplebucket?notification= HTTP/1.1 User-Agent: s3curl 2.0 Host: s3.amazonaws.com Pragma: no-cache Accept: */* Proxy-Connection: Keep-Alive Authorization:
authorization string
Date: Mon, 13 Oct 2014 23:14:52 +0000 Content-Length:length
[request body]
The following is a sample response.
HTTP/1.1 200 OK x-amz-id-2: 8+FlwagBSoT2qpMaGlfCUkRkFR5W3OeS7UhhoBb17j+kqvpS2cSFlgJ5coLd53d2 x-amz-request-id: E5BA4600A3937335 Date: Fri, 31 Oct 2014 01:49:50 GMT Content-Length: 0 Server: AmazonS3
Example 2: Configure a Notification with Multiple Destinations
The following notification configuration includes the topic and queue configurations:
-
A topic configuration identifying an SNS topic for Amazon S3 to publish events of the
s3:ReducedRedundancyLostObject
type. -
A queue configuration identifying an SQS queue for Amazon S3 to publish events of the
s3:ObjectCreated:*
type.
<NotificationConfiguration> <TopicConfiguration> <Topic>arn:aws:sns:us-east-1:356671443308:s3notificationtopic2</Topic> <Event>s3:ReducedRedundancyLostObject</Event> </TopicConfiguration> <QueueConfiguration> <Queue>arn:aws:sqs:us-east-1:356671443308:s3notificationqueue</Queue> <Event>s3:ObjectCreated:*</Event> </QueueConfiguration> </NotificationConfiguration>
The following PUT request against the notification subresource of the
examplebucket
bucket sends the preceding notification configuration
in the request body. The operation replaces the existing notification configuration
on the bucket.
PUT http://s3.amazonaws.com/examplebucket?notification= HTTP/1.1 User-Agent: s3curl 2.0 Host: s3.amazonaws.com Pragma: no-cache Accept: */* Proxy-Connection: Keep-Alive Authorization:
authorization string
Date: Mon, 13 Oct 2014 22:58:43 +0000 Content-Length: 391 Expect: 100-continue
The following is a sample response.
HTTP/1.1 200 OK x-amz-id-2: SlvJLkfunoAGILZK3KqHSSUq4kwbudkrROmESoHOpDacULy+cxRoR1Svrfoyvg2A x-amz-request-id: BB1BA8E12D6A80B7 Date: Mon, 13 Oct 2014 22:58:44 GMT Content-Length: 0 Server: AmazonS3
Example 3: Configure a Notification with Object Key Name Filtering
The following notification configuration contains a queue configuration identifying
an Amazon SQS queue
for Amazon S3 to publish events to of the s3:ObjectCreated:Put
type. The events will be published
whenever an object that has a prefix of images/
and a .jpg
suffix is PUT to a bucket.
For more examples of notification configurations that use filtering, go to Configuring Event Notifications in the Amazon Simple Storage Service Developer Guide.
<NotificationConfiguration> <QueueConfiguration> <Id>1</Id> <Filter> <S3Key> <FilterRule> <Name>prefix</Name> <Value>
images/
</Value> </FilterRule> <FilterRule> <Name>suffix</Name> <Value>.jpg
</Value> </FilterRule> </S3Key> </Filter> <Queue>arn:aws:sqs:us-west-2:444455556666:s3notificationqueue</Queue> <Event>s3:ObjectCreated:Put</Event> </QueueConfiguration> </NotificationConfiguration>
The following PUT request against the notification subresource of the
examplebucket
bucket sends the preceding notification configuration
in the request body. The operation replaces the existing notification configuration
on the bucket.
PUT http://s3.amazonaws.com/examplebucket?notification= HTTP/1.1 User-Agent: s3curl 2.0 Host: s3.amazonaws.com Pragma: no-cache Accept: */* Proxy-Connection: Keep-Alive Authorization:
authorization string
Date: Mon, 13 Oct 2014 22:58:43 +0000 Content-Length:length
Expect: 100-continue
The following is a sample response.
HTTP/1.1 200 OK x-amz-id-2: SlvJLkfunoAGILZK3KqHSSUq4kwbudkrROmESoHOpDacULy+cxRoR1Svrfoyvg2A x-amz-request-id: BB1BA8E12D6A80B7 Date: Mon, 13 Oct 2014 22:58:44 GMT Content-Length: 0 Server: AmazonS3