My goal is to read data from kinesis and upload csv file on s3, but in csv file arrow(=>) is coming in json data insted of colon(:)
Logstash config file
input {
kinesis {
application_name => "logstash"
kinesis_stream_name => "events"
type => "kinesis"
region => "us-east-1"
profile => "default"
metrics => "cloudwatch"
codec => "json"
}
}
filter {
grok {
match => { "[data][ti]" => "%{YEAR:event_year}-%{MONTHNUM2:event_month}-%{MONTHDAY:event_day}" }
}
}
output {
s3 {
bucket => "test-logstash"
region => "us-east-1"
prefix => "%{event_year}/%{event_month}/%{event_day}/%{[data][brandid]}/%{[data][event_name]}"
encoding => "none"
codec => csv {
separator => "␁"
}
size_file => 200000000
time_file => 60
}
}
2
Answers
When writing your Hash to the CSV file, convert it to JSON using
as_json
or a JSON string usingto_json
.You can use the mutate filter in Logstash to replace "arrow (=>)" with "colon (:)".
In the filter section, the mutate filter is used to perform a global substitution (gsub) to replace "arrow (=>)" with "colon (:)". This should ensure that your JSON data is correctly processed as expected.
Make sure to adjust the field name (message) in the mutate filter if your JSON data is located in a different field.