https://github.com/fluent/fluent-plugin-s3
With fluentd v0.14 and fluent-plugin-s3 v1.0.0, use new buffer configuration to dynamic parameters.
<match pattern>@type s3aws_key_id YOUR_AWS_KEY_IDaws_sec_key YOUR_AWS_SECRET_KEYs3_bucket YOUR_S3_BUCKET_NAMEs3_region ap-northeast-1path logs/${tag}/%Y/%m/%d/s3_object_key_format %{path}%{time_slice}_%{index}.%{file_extension}# if you want to use ${tag} or %Y/%m/%d/ like syntax in path / s3_object_key_format,# need to specify tag for ${tag} and time for %Y/%m/%d in <buffer> argument.<buffer tag,time>@type filepath /var/log/fluent/s3timekey 3600 # 1 hour partitiontimekey_wait 10mtimekey_use_utc true # use utc</buffer><format>@type json</format></match>
https://devtron.ai/blog/pushing-k8s-cluster-logs-s3-bucket-fluentd/
general.conf: |# Prevent fluentd from handling records containing its own logs. Otherwise# it can lead to an infinite loop, when error in sending one message generates# another message which also fails to be sent and so on.<match fluentd.**>@type null</match># Used for health checking<source>@type httpport 9880bind 0.0.0.0</source># Emits internal metrics to every minute, and also exposes them on port# 24220. Useful for determining if an output plugin is retryring/erroring,# or determining the buffer queue length.<source>@type monitor_agentbind 0.0.0.0port 24220tag fluentd.monitor.metrics</source>system.conf: |-<system>root_dir /tmp/fluentd-buffers/</system>forward-input.conf: |<source>@type forwardport 24224bind 0.0.0.0</source>output.conf: |<filter kube.**>@type record_transformerenable_ruby<record>kubernetes_tag ${"%s" % [record["kubernetes"]["labels"]["app"] || record["kubernetes"]["labels"]["k8s-app"] || record["kubernetes"]["labels"]["name"] || "unspecified-app-label"]}</record></filter><match kube.**>@type rewrite_tag_filter<rule>key kubernetes_tagpattern ^(.+)$tag $1</rule></match><match **>@type s3s3_bucket <k8s-logs-bucket>s3_region <ap-southeast-1>s3_object_key_format "${tag}/%{time_slice}-events_%{index}.%{file_extension}"time_slice_format %Y/%m/%d/%Htime_slice_wait 10mpath test-logs# if you want to use ${tag} or %Y/%m/%d/ like syntax in path / s3_object_key_format,# need to specify tag for ${tag} and time for %Y/%m/%d in <buffer> argument.<buffer tag,time>@type fileflush_mode intervalflush_interval 30spath /var/log/fluent/s3timekey 300 # 1 hour partitiontimekey_wait 1mtimekey_use_utc true # use utcchunk_limit_size 100m</buffer><format>@type json</format></match>
