PHP S3 Logs Parser


June 19th, 2020


S3 Logs Parser is a PHP package by Alex Kolev to analyze and query AWS S3 access logs quickly. The detailed usage report includes stats for downloads and the number of bytes transferred.

This package provides a convenience class for parsing these logs with minimal effort on your part. Once you enable server access logging on an S3 bucket, here’s the gist of how you would use this package to get stats for the bucket:

1use S3LogsParser\S3LogsParser;
3$S3LogsParser = new S3LogsParser([
4 'version' => 'latest',
5 'region' => $awsBucketRegion,
6 'access_key' => $awsAccessKey,
7 'secret_key' => $awsSecretKey,
10$S3LogsParser->getStats($awsBucketName, $awsBucketPrefix, $date);

The getStats method returns a JSON-formatted string of the S3 log data:

2 "success":true,
3 "statistics":{
4 "bucket":"bn-test",
5 "prefix":"bp-2018-10-31",
6 "data":{
7 "test.png":{
8 "downloads":4,
9 "bandwidth":4096
10 },
11 "test2.png":{
12 "downloads":2,
13 "bandwidth":2048
14 }
15 }
16 }

Learn More

You can learn more about this package, get full installation instructions, and view the source code on GitHub at mtrdesign/s3-logs-parser.

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.

Laravel News Partners