How to Configure S3 Object Storage Access Logs

Access logs record requests made to an S3-compatible storage Space. They help you investigate storage activity, troubleshoot access issues, and understand how files are being accessed.

In Cyberin S3 Object Storage, access logging can record requests such as reading, uploading, and deleting objects. Logs can also capture requests made through supported CDN endpoints when the CDN is enabled.

Access logs are useful when you need to investigate unexpected file access, review request activity, or analyze traffic to files served from object storage.

Step 1: Identify the Source and Destination Spaces

Choose two Spaces:

For example, you might monitor website-assets and store its logs in website-access-logs.

In the below commands, use your real Space names. The Space destination should be private and accessible only to authorised users.

Step 2: Configure the S3-Compatible Endpoint

Use the endpoint of the region your Space is in.

For example, if your Space is in the sgp1 region, use:

https://sgp1.digitaloceanspaces.com

Replace sgp1 with your actual region.

Ensure that the AWS CLI is configured with valid S3-compatible credentials before proceeding. Do not include your secret key directly in command examples or publish it in scripts.

Step 3: Create the Logging Configuration File

Create a file named logging-config.json containing the following configuration:

{
  "LoggingEnabled": {
    "TargetBucket": "YOUR_LOG_SPACE_NAME",
    "TargetPrefix": "access-logs/"
  }
}

Replace YOUR_LOG_SPACE_NAME with the name of the destination Space.

The configuration fields serve the following purposes:

For example, access-logs/ groups the generated log objects under a common prefix.

Step 4: Enable Access Logging

To apply the logging configuration, run the following AWS CLI command:

aws --endpoint-url https://YOUR_REGION.digitaloceanspaces.com \
  s3api put-bucket-logging \
  --bucket YOUR_SOURCE_SPACE_NAME \
  --bucket-logging-status file://logging-config.json

Replace YOUR_REGION and YOUR_SOURCE_SPACE_NAME with the appropriate values.

On success, the CLI typically outputs nothing and exits with a status of zero.

This enables logging of access to the source Space. It does not immediately generate a log file . Once requests have been logged , the delivery of the logs is asynchronous .

Step 5: Verify the Logging Configuration

Use the following command to check whether logging is enabled:

aws --endpoint-url https://YOUR_REGION.digitaloceanspaces.com \
  s3api get-bucket-logging \
  --bucket YOUR_SOURCE_SPACE_NAME

If logging is enabled, the response should include a LoggingEnabled section that includes the destination Space and log prefix.

For example:

{
  "LoggingEnabled": {
    "TargetBucket": "YOUR_LOG_SPACE_NAME",
    "TargetPrefix": "access-logs/"
  }
}

Make sure that the Space and prefix set are the intended ones to be configured.

Step 6: Locate and Review the Log Files

Once logging is enabled, allow the service some time to collect and deliver the logs.

Then:

Log delivery async. Usually logs arrive within an hour, but can take two hours or longer to deliver. Just because you don’t have a log file right after you enable logging doesn’t mean there’s a problem with your configuration.

Origin access logs are in the Amazon S3 server access log format. CDN access logs are in the format of Amazon CloudFront access logs.

Step 7: Disable Access Logging When No Longer Required

To stop logging requests, run the command:

aws --endpoint-url https://YOUR_REGION.digitaloceanspaces.com \
  s3api put-bucket-logging \
  --bucket YOUR_SOURCE_SPACE_NAME \
  --bucket-logging-status '{}'

This removes the source Space logging configuration.

Run the get-bucket-logging command again to confirm that logging is disabled. An empty JSON response means no logging configuration set.

Turning off logging does not automatically delete log files already stored in the destination Space.

Troubleshooting

Access denied when enabling logging: Check your access key's permissions. Configuring access logs requires the appropriate bucket-level permissions, and the destination Space must allow the service to write log objects.

No log files appear: Allow sufficient time for asynchronous delivery. Confirm the destination Space, target prefix, regional endpoint, and logging configuration.

The source and destination Space are the same: Use a separate destination Space. Sending access logs to the source Space is not supported.

The configuration command fails: Check that the JSON file is valid, the file path is correct, and the source Space name and endpoint match your configuration.

CDN requests are not easy to identify: Review the appropriate log format. Origin and CDN logs use different formats, and they may be stored under the same destination prefix when CDN logging is enabled.