Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

S3 data partitioning for bucket logging files

I have a s3 bucket "ABC" and logging is enabled at this bucket and logs stored in "ABC-logs". There are many files comes in "ABC-logs" per day. Now I want to segregate these logs year wise. For ex:

s3://ABC-logs/year=2015
s3://ABC-logs/year=2016
s3://ABC-logs/year=2017

What is the best way to do this. I thought to do it via awscli but each year end, I will have to change bucket logging folder.

like image 957
ajaysheoran2323 Avatar asked Mar 07 '23 16:03

ajaysheoran2323


2 Answers

The traditional way to do this is via an Amazon EMR cluster.

You can use Hive to create an EXTERNAL TABLE pointing at your source data. Then, create another EXTERNAL TABLE pointing to where you would like to store the data, with appropriate parameters such as Partition and filetype. Then, select data from the first table and insert it into the destination table.

Partitioned data is more efficient for querying since whole folders can be skipped if it is known that the data is not necessary for the query.

like image 114
John Rotenstein Avatar answered Mar 24 '23 16:03

John Rotenstein


S3 supports events, so create and set the logs to the folder say newObjects s3://ABC-logs/newObjects and enable a event with newobjects prefix (/newObjects) with lambda notification , Inside lambda receive the object key and move it with the current year prefix like (s3://ABC-logs/year=2017/objectname).

like image 21
Madhan S Avatar answered Mar 24 '23 14:03

Madhan S