- Navigation GuideYou are on a Command (operation) page with structural examples. Use the navigation breadcrumb if you would like to return to the Client landing page.
PutBucketLoggingCommand
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 GranteesEmail DisplayNameis optional and ignored in the request. -
By Email address:
Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="AmazonCustomerByEmail"Granteesemail.com The grantee is resolved to the
CanonicalUserand, in a response to aGETObjectAclrequest, appears as the CanonicalUser. -
By URI:
Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Group"http://acs.amazonaws.com/groups/global/AuthenticatedUsers
-
To enable logging, you use LoggingEnabled and its children request elements. To disable logging, you use an empty BucketLoggingStatus request element:
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.
Example Syntax
Use a bare-bones client and the command you need to make an API call.
import { S3Client, PutBucketLoggingCommand } from "@aws-sdk/client-s3"; // ES Modules import
// const { S3Client, PutBucketLoggingCommand } = require("@aws-sdk/client-s3"); // CommonJS import
// import type { S3ClientConfig } from "@aws-sdk/client-s3";
const config = {}; // type is S3ClientConfig
const client = new S3Client(config);
const input = { // PutBucketLoggingRequest
Bucket: "STRING_VALUE", // required
BucketLoggingStatus: { // BucketLoggingStatus
LoggingEnabled: { // LoggingEnabled
TargetBucket: "STRING_VALUE", // required
TargetGrants: [ // TargetGrants
{ // TargetGrant
Grantee: { // Grantee
DisplayName: "STRING_VALUE",
EmailAddress: "STRING_VALUE",
ID: "STRING_VALUE",
URI: "STRING_VALUE",
Type: "CanonicalUser" || "AmazonCustomerByEmail" || "Group", // required
},
Permission: "FULL_CONTROL" || "READ" || "WRITE",
},
],
TargetPrefix: "STRING_VALUE", // required
TargetObjectKeyFormat: { // TargetObjectKeyFormat
SimplePrefix: {},
PartitionedPrefix: { // PartitionedPrefix
PartitionDateSource: "EventTime" || "DeliveryTime",
},
},
},
},
ContentMD5: "STRING_VALUE",
ChecksumAlgorithm: "CRC32" || "CRC32C" || "SHA1" || "SHA256" || "CRC64NVME",
ExpectedBucketOwner: "STRING_VALUE",
};
const command = new PutBucketLoggingCommand(input);
const response = await client.send(command);
// {};
Example Usage
PutBucketLoggingCommand Input
Parameter | Type | Description |
|---|
Parameter | Type | Description |
|---|---|---|
BucketRequired | string | undefined | The name of the bucket for which to set the logging parameters. Note: To supply the Multi-region Access Point (MRAP) to Bucket, you need to install the "aws-sdk/signature-v4-crt" package to your project dependencies. For more information, please go to https://github.com/aws/aws-sdk-js-v3#known-issues |
BucketLoggingStatusRequired | BucketLoggingStatus | undefined | Container for logging status information. |
ChecksumAlgorithm | ChecksumAlgorithm | undefined | Indicates the algorithm used to create the checksum for the request when you use the SDK. This header will not provide any additional functionality if you don't use the SDK. When you send this header, there must be a corresponding If you provide an individual checksum, Amazon S3 ignores any provided |
ContentMD5 | string | undefined | The MD5 hash of the For requests made using the Amazon Web Services Command Line Interface (CLI) or Amazon Web Services SDKs, this field is calculated automatically. |
ExpectedBucketOwner | string | undefined | 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 |
PutBucketLoggingCommand Output
Parameter | Type | Description |
|---|
Parameter | Type | Description |
|---|---|---|
$metadataRequired | ResponseMetadata | Metadata pertaining to this request. |
Throws
Name | Fault | Details |
|---|
Name | Fault | Details |
|---|---|---|
| S3ServiceException | Base exception class for all service exceptions from S3 service. |