This operation is not supported for directory buckets.
Enables notifications of specified events for a bucket. For more information about event notifications, seeConfiguring Event Notifications.
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 emptyNotificationConfiguration.
<NotificationConfiguration>
</NotificationConfiguration>
This action 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, seeConfiguring Notifications for Amazon S3 Events.
You can disable notifications by adding the empty NotificationConfiguration element.
For more information about the number of event notification configurations that you can create per bucket, seeAmazon S3 service quotas in AWS General Reference.
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 the requireds3:PutBucketNotification permission.
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 action will fail, and Amazon S3 will not add the configuration to your bucket.
If the configuration in the request body includes only oneTopicConfiguration specifying only thes3:ReducedRedundancyLostObject event type, the response will also include thex-amz-sns-test-message-id header containing the message ID of the test notification sent to the topic.
The following action is related toPutBucketNotificationConfiguration:
You must URL encode any signed header values that contain spaces. For example, if your header value ismy file.txt, containing two spaces aftermy, you must URL encode this value tomy%20%20file.txt.
PUT /?notification HTTP/1.1Host:Bucket.s3.amazonaws.comx-amz-expected-bucket-owner:ExpectedBucketOwnerx-amz-skip-destination-validation:SkipDestinationValidation<?xml version="1.0" encoding="UTF-8"?><NotificationConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <TopicConfiguration> <Event>string</Event> ... <Filter> <S3Key> <FilterRule> <Name>string</Name> <Value>string</Value> </FilterRule> ... </S3Key> </Filter> <Id>string</Id> <Topic>string</Topic> </TopicConfiguration> ... <QueueConfiguration> <Event>string</Event> ... <Filter> <S3Key> <FilterRule> <Name>string</Name> <Value>string</Value> </FilterRule> ... </S3Key> </Filter> <Id>string</Id> <Queue>string</Queue> </QueueConfiguration> ... <CloudFunctionConfiguration> <Event>string</Event> ... <Filter> <S3Key> <FilterRule> <Name>string</Name> <Value>string</Value> </FilterRule> ... </S3Key> </Filter> <Id>string</Id> <CloudFunction>string</CloudFunction> </CloudFunctionConfiguration> ... <EventBridgeConfiguration> </EventBridgeConfiguration></NotificationConfiguration>The request uses the following URI parameters.
The name of the bucket.
Required: Yes
The account ID of the expected bucket owner. If the account ID that you provide does not match the actual owner of the bucket, the request fails with the HTTP status code403 Forbidden (access denied).
Skips validation of Amazon SQS, Amazon SNS, and AWS Lambda destinations. True or false value.
The request accepts the following data in XML format.
Root level tag for the NotificationConfiguration parameters.
Required: Yes
Describes the AWS Lambda functions to invoke and the events for which to invoke them.
Type: Array ofLambdaFunctionConfiguration data types
Required: No
Enables delivery of events to Amazon EventBridge.
Type:EventBridgeConfiguration data type
Required: No
The Amazon Simple Queue Service queues to publish messages to and the events for which to publish messages.
Type: Array ofQueueConfiguration data types
Required: No
The topic to which notifications are sent and the events for which notifications are generated.
Type: Array ofTopicConfiguration data types
Required: No
HTTP/1.1 200If the action is successful, the service sends back an HTTP 200 response with an empty HTTP body.
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 action replaces the existing notification configuration.
PUT http://s3.<Region>.amazonaws.com/examplebucket?notification= HTTP/1.1User-Agent: s3curl 2.0Host: s3.amazonaws.comPragma: no-cacheAccept: */*Proxy-Connection: Keep-AliveAuthorization: authorization stringDate: Mon, 13 Oct 2014 23:14:52 +0000Content-Length: length[request body]This example illustrates one usage of PutBucketNotificationConfiguration.
HTTP/1.1 200 OKx-amz-id-2: 8+FlwagBSoT2qpMaGlfCUkRkFR5W3OeS7UhhoBb17j+kqvpS2cSFlgJ5coLd53d2x-amz-request-id: E5BA4600A3937335Date: Fri, 31 Oct 2014 01:49:50 GMTContent-Length: 0Server: AmazonS3The following notification configuration includes the topic and queue configurations:
A topic configuration identifying an SNS topic for Amazon S3 to publish events of thes3:ReducedRedundancyLostObject type.
A queue configuration identifying an SQS queue for Amazon S3 to publish events of thes3: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 theexamplebucket bucket sends the preceding notification configuration in the request body. The action replaces the existing notification configuration on the bucket.
PUT http://s3.<Region>.amazonaws.com/examplebucket?notification= HTTP/1.1User-Agent: s3curl 2.0Host: s3.amazonaws.comPragma: no-cacheAccept: */*Proxy-Connection: Keep-AliveAuthorization: authorization stringDate: Mon, 13 Oct 2014 22:58:43 +0000Content-Length: 391Expect: 100-continueThe following notification configuration contains a queue configuration identifying an Amazon SQS queue for Amazon S3 to publish events to of thes3:ObjectCreated:Put type. The events will be published whenever an object that has a prefix ofimages/ and a.jpg suffix is PUT to a bucket. For more examples of notification configurations that use filtering, seeConfiguring Event Notifications.
<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 theexamplebucket bucket sends the preceding notification configuration in the request body. The action replaces the existing notification configuration on the bucket.
PUT http://s3.<Region>.amazonaws.com/examplebucket?notification= HTTP/1.1User-Agent: s3curl 2.0Host: s3.amazonaws.comPragma: no-cacheAccept: */*Proxy-Connection: Keep-AliveAuthorization: authorization stringDate: Mon, 13 Oct 2014 22:58:43 +0000Content-Length: lengthExpect: 100-continueThis example illustrates one usage of PutBucketNotificationConfiguration.
HTTP/1.1 200 OKx-amz-id-2: SlvJLkfunoAGILZK3KqHSSUq4kwbudkrROmESoHOpDacULy+cxRoR1Svrfoyvg2Ax-amz-request-id: BB1BA8E12D6A80B7Date: Mon, 13 Oct 2014 22:58:44 GMTContent-Length: 0Server: AmazonS3For more information about using this API in one of the language-specific AWS SDKs, see the following: