Skip to content

Instantly share code, notes, and snippets.

@derrickturk
Created September 23, 2025 17:15
Show Gist options
  • Save derrickturk/bd692235173ac8add56fc0eeba036e94 to your computer and use it in GitHub Desktop.
Save derrickturk/bd692235173ac8add56fc0eeba036e94 to your computer and use it in GitHub Desktop.
S3 access logs to CSV
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "s3-log-parse",
# ]
# ///
import argparse
import sys
import csv
from s3logparse import s3logparse
def main():
"""
Command line tool for processing S3 access logs
"""
argparser = argparse.ArgumentParser()
argparser.add_argument(
'infile',
nargs='?',
type=argparse.FileType('r'),
default=sys.stdin
)
args = argparser.parse_args()
csv_writer = csv.writer(sys.stdout)
csv_writer.writerow((
'bucket_owner',
'bucket',
'timestamp',
'remote_ip',
'requester',
'request_id',
'operation',
's3_key',
'request_uri',
'status_code',
'error_code',
'bytes_sent',
'object_size',
'total_time',
'turn_around_time',
'referrer',
'user_agent',
'version_id',
))
csv_writer.writerows(s3logparse.parse_to_tuples(args.infile.readlines()))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment