I've written a script to continuously pull all my S3 bucket logfiles down to my Logstash server, so it can be parsed using the patterns in this pull request. Alas, given the script recreates the logfile from scratch instead of just appending to it, Logstash's file
input isn't seeing any new changes. Any ideas?
Script below:
#!/usr/bin/ruby
require 'rubygems'
require 'aws/s3'
# for non-us buckets, we need to change the endpoint
AWS.config(:s3_endpoint => "s3-eu-west-1.amazonaws.com")
# connect to S3
s3 = AWS::S3.new(:access_key_id => S3_ACCESS_KEY, :secret_access_key => S3_SECRET_KEY)
# grab the bucket where the logs are stored
bucket = s3.buckets[BUCKET_NAME]
File.open("/var/log/s3_bucket.log", 'w') do |file|
# grab all the objects in the bucket, can also use a prefix here and limit what S3 returns
bucket.objects.with_prefix('staticassets-logs/').each do |log|
log.read do |line|
file.write(line)
end
end
end
Any help? Thanks!