putBucketLogging  
  End of support notice: As of October 1, 2025, Amazon S3 has discontinued support for Email Grantee Access Control Lists (ACLs). If you attempt to use an Email Grantee ACL in a request after October 1, 2025, the request will receive an HTTP 405 (Method Not Allowed) error.
This change affects the following Amazon Web Services Regions: US East (N. Virginia), US West (N. California), US West (Oregon), Asia Pacific (Singapore), Asia Pacific (Sydney), Asia Pacific (Tokyo), Europe (Ireland), and South America (São Paulo).
This operation is not supported for directory buckets.
Set the logging parameters for a bucket and to specify permissions for who can view and modify the logging parameters. All logs are saved to buckets in the same Amazon Web Services Region as the source bucket. To set the logging status of a bucket, you must be the bucket owner.
The bucket owner is automatically granted FULL_CONTROL to all logs. You use the Grantee request element to grant access to other people. The Permissions request element specifies the kind of access the grantee has to the logs.
If the target bucket for log delivery uses the bucket owner enforced setting for S3 Object Ownership, you can't use the Grantee request element to grant access to others. Permissions can only be granted using policies. For more information, see Permissions for server access log delivery in the Amazon S3 User Guide.
Grantee Values
You can specify the person (grantee) to whom you're assigning access rights (by using request elements) in the following ways. For examples of how to specify these grantee values in JSON format, see the Amazon Web Services CLI example in Enabling Amazon S3 server access logging in the Amazon S3 User Guide.
- By the person's ID: - <Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser"><ID><>ID<></ID><DisplayName><>GranteesEmail<></DisplayName> </Grantee>``DisplayNameis optional and ignored in the request.
- By Email address: - <Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="AmazonCustomerByEmail"><EmailAddress><>Grantees@email.com<></EmailAddress></Grantee>The grantee is resolved to the- CanonicalUserand, in a response to a- GETObjectAclrequest, appears as the CanonicalUser.
- By URI: - <Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Group"><URI><>http://acs.amazonaws.com/groups/global/AuthenticatedUsers<></URI></Grantee>
To enable logging, you use LoggingEnabled and its children request elements. To disable logging, you use an empty BucketLoggingStatus request element:
<BucketLoggingStatus xmlns="http://doc.s3.amazonaws.com/2006-03-01" />
For more information about server access logging, see Server Access Logging in the Amazon S3 User Guide.
For more information about creating a bucket, see CreateBucket. For more information about returning the logging status of a bucket, see GetBucketLogging.
The following operations are related to PutBucketLogging:
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.
Samples
import aws.sdk.kotlin.services.s3.model.BucketLoggingStatus
import aws.sdk.kotlin.services.s3.model.BucketLogsPermission
import aws.sdk.kotlin.services.s3.model.Grantee
import aws.sdk.kotlin.services.s3.model.LoggingEnabled
import aws.sdk.kotlin.services.s3.model.TargetGrant
import aws.sdk.kotlin.services.s3.model.Type
fun main() { 
   //sampleStart 
   // The following example sets logging policy on a bucket. For the Log Delivery group to deliver logs to
// the destination bucket, it needs permission for the READ_ACP action which the policy grants.
s3Client.putBucketLogging {
    bucket = "sourcebucket"
    bucketLoggingStatus = BucketLoggingStatus {
        loggingEnabled = LoggingEnabled {
            targetBucket = "targetbucket"
            targetPrefix = "MyBucketLogs/"
            targetGrants = listOf<TargetGrant>(
                TargetGrant {
                    grantee = Grantee {
                        type = Type.fromValue("Group")
                        uri = "http://acs.amazonaws.com/groups/global/AllUsers"
                    }
                    permission = BucketLogsPermission.fromValue("READ")
                }                    
            )
        }
    }
} 
   //sampleEnd
}