Skip to content

put_bucket_notification_configuration async

put_bucket_notification_configuration(
    bucket: BucketName,
    notification_configuration: NotificationConfiguration,
    *,
    config_overrides: Optional[AsyncS3ClientConfig] = None,
    expected_bucket_owner: Optional[AccountId] = None,
    skip_destination_validation: Optional[SkipValidation] = None,
) -> None

This operation is not supported for directory buckets.

Enables notifications of specified events for a bucket. For more information about event notifications, see Configuring 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 empty 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 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, see Configuring 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, see Amazon S3 service quotas in Amazon Web Services 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 required s3: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 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 the topic.

The following action is related to PutBucketNotificationConfiguration:

You must URL encode any signed header values that contain spaces. For example, if your header value is my file.txt, containing two spaces after my, you must URL encode this value to my%20%20file.txt.

Parameters:

  • bucket (BucketName) –

    The name of the bucket.

  • expected_bucket_owner (Optional[AccountId], default: None ) –

    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 code 403 Forbidden (access denied).

  • skip_destination_validation (Optional[SkipValidation], default: None ) –

    Skips validation of Amazon SQS, Amazon SNS, and Lambda destinations. True or false value.

Raises:

Examples:

Set notification configuration for a bucket The following example sets notification configuration on a bucket to publish the object created events to an SNS topic.

>>> await client.put_bucket_notification_configuration(bucket='examplebucket', notification_configuration={'TopicConfigurations': [{'TopicArn': 'arn:aws:sns:us-west-2:123456789012:s3-notification-topic', 'Events': ['s3:ObjectCreated:*']}]})
Source code in docs_src/capo_s3/_services/async_s3.py
async def put_bucket_notification_configuration(
    self,
    bucket: "capo_s3.types.bucket_name.BucketName",
    notification_configuration: "capo_s3.types.notification_configuration.NotificationConfiguration",
    *,
    config_overrides: Optional[AsyncS3ClientConfig] = None,
    expected_bucket_owner: Optional["capo_s3.types.account_id.AccountId"] = None,
    skip_destination_validation: Optional[
        "capo_s3.types.skip_validation.SkipValidation"
    ] = None,
) -> None:
    """<note> <p>This operation is not supported for directory buckets.</p> </note> <p>Enables notifications of specified events for a bucket. For more information about event notifications, see <a href="https://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html">Configuring Event Notifications</a>.</p> <p>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.</p> <p>By default, your bucket has no event notifications configured. That is, the notification configuration will be an empty <code>NotificationConfiguration</code>.</p> <p> <code><NotificationConfiguration></code> </p> <p> <code></NotificationConfiguration></code> </p> <p>This action replaces the existing notification configuration with the configuration you include in the request body.</p> <p>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 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, see <a href="https://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html">Configuring Notifications for Amazon S3 Events</a>.</p> <p>You can disable notifications by adding the empty NotificationConfiguration element.</p> <p>For more information about the number of event notification configurations that you can create per bucket, see <a href="https://docs.aws.amazon.com/general/latest/gr/s3.html#limits_s3">Amazon S3 service quotas</a> in <i>Amazon Web Services General Reference</i>.</p> <p>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 required <code>s3:PutBucketNotification</code> permission.</p> <note> <p>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.</p> </note> <p>If the configuration in the request body includes only one <code>TopicConfiguration</code> specifying only the <code>s3:ReducedRedundancyLostObject</code> event type, the response will also include the <code>x-amz-sns-test-message-id</code> header containing the message ID of the test notification sent to the topic.</p> <p>The following action is related to <code>PutBucketNotificationConfiguration</code>:</p> <ul> <li> <p> <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetBucketNotificationConfiguration.html">GetBucketNotificationConfiguration</a> </p> </li> </ul> <important> <p>You must URL encode any signed header values that contain spaces. For example, if your header value is <code>my file.txt</code>, containing two spaces after <code>my</code>, you must URL encode this value to <code>my%20%20file.txt</code>.</p> </important>

    Args:
        bucket: <p>The name of the bucket.</p>
        expected_bucket_owner: <p>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 code <code>403 Forbidden</code> (access denied).</p>
        skip_destination_validation: <p>Skips validation of Amazon SQS, Amazon SNS, and Lambda destinations. True or false value.</p>

    Raises:
        capo_s3.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        Set notification configuration for a bucket
        The following example sets notification configuration on a bucket to publish the object created events to an SNS topic.

        >>> await client.put_bucket_notification_configuration(bucket='examplebucket', notification_configuration={'TopicConfigurations': [{'TopicArn': 'arn:aws:sns:us-west-2:123456789012:s3-notification-topic', 'Events': ['s3:ObjectCreated:*']}]})
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_s3.types.put_bucket_notification_configuration_request.PutBucketNotificationConfigurationRequest]",
    ) -> AsyncOperationResponse[None]:
        import capo_s3._operations.amazon_s3.put_bucket_notification_configuration

        (
            output,
            http_response,
        ) = await capo_s3._operations.amazon_s3.put_bucket_notification_configuration.async_put_bucket_notification_configuration(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("PutBucketNotificationConfiguration")
    )
    input_: capo_s3.types.put_bucket_notification_configuration_request.PutBucketNotificationConfigurationRequest = {
        "bucket": bucket,
        "notification_configuration": notification_configuration,
    }
    if expected_bucket_owner is not None:
        input_["expected_bucket_owner"] = expected_bucket_owner
    if skip_destination_validation is not None:
        input_["skip_destination_validation"] = skip_destination_validation

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output