Remove log files on aws s3 (rails7)
Cron job is better in case you have some conditional logics for the number of logs, otherwise s3 automation. If you go for cron jobs, you have to handle monitoring to check if jobs fail or not. Check here for more info.

Which option is better to remove log files on aws s3 for rails7? s3 automation vs cron job
I wrote some rake tasks.
task :delete_stale_logs do
    s3 = Aws::S3::Resource.new(
      region: ENV['AWS_REGION'],
      access_key_id: ENV['AWS_ACCESS_KEY_ID'],
      secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
    )

    bucket = s3.bucket(ENV['AWS_BUCKET'])

    bucket.objects.each do |object|
      if object.key.include?('.log') && object.last_modified < Time.now - 30.days
        object.delete
        puts "Deleted #{object.key}"
      end
    end
  end
end

