mtrdesign / s3-logs-parser
S3 Logs Parser
Installs: 466
Dependents: 0
Suggesters: 0
Security: 0
Stars: 35
Watchers: 3
Forks: 1
Open Issues: 2
pkg:composer/mtrdesign/s3-logs-parser
Requires
- php: ^7.4|^8.0
- ext-json: *
- aws/aws-sdk-php: ^3.100
- nesbot/carbon: ^2.19
Requires (Dev)
- mockery/mockery: ^1.2
- phpstan/phpstan: ^0.12
- phpunit/phpunit: ^7.5
- squizlabs/php_codesniffer: ^3.4
This package is auto-updated.
Last update: 2025-10-22 02:57:08 UTC
README
AWS S3 Logs Parser is a simple PHP package to parse Amazon Simple Storage Service (Amazon S3) logs into a readable JSON format. The detailed usage report will show you how much times a file is downloaded and how much bytes are transferred.
Getting Started
- Sign up for AWS – Before you begin, you need to sign up for an AWS account and retrieve your AWS credentials.
- Create your own bucket – Now that you've signed up for Amazon S3, you're ready to create a bucket using the AWS Management Console.
- Enable server access logging – When you enable logging, Amazon S3 delivers access logs for a source bucket to a target bucket that you choose.
- Install the service – Using Composer is the recommended way to install it. The service is available via Packagist under the
mtrdesign/s3-logs-parserpackage.
$ composer require mtrdesign/s3-logs-parser
Usage
Create a service instance:
<?php use S3LogsParser\S3LogsParser; $S3LogsParser = new S3LogsParser([ 'version' => 'latest', 'region' => $awsBucketRegion, 'access_key' => $awsAccessKey, 'secret_key' => $awsSecretKey, ]); ?>
Optionally, you can set and update service configurations via setConfigs() method:
<?php $S3LogsParser->setConfigs([ 'version' => 'latest', 'region' => $awsBucketRegion, 'access_key' => $awsAccessKey, 'secret_key' => $awsSecretKey, ]); ?>
Finally, you can get file's download and bandwidth statistics for a specific date in this way:
<?php $S3LogsParser->getStats($awsBucketName, $awsBucketPrefix, $date); ?>
It is recommended to pass Carbon date string to this method.
This is how service response should look like:
{
"success":true,
"statistics":{
"bucket":"bn-test",
"prefix":"bp-2018-10-31",
"data":{
"test.png":{
"downloads":4,
"bandwidth":4096
},
"test2.png":{
"downloads":2,
"bandwidth":2048
}
}
}
}
Contributing
Ensure all the guides are followed and style/test checkers pass before pushing your code.
Requirements
Installation steps
- Build the required services and Docker container with
$ make docker-build - SSH into the container with
$ make docker-bash - Confirm code style checker passes with
$ make run-phpcs - Confirm code quality checker passes with
$ make run-phpstan - Confirm code texts checker passes with
$ make run-phpunit
License
AWS S3 Logs Parser is open source and available under the MIT License.