diff --git a/bin/summarize-user-events b/bin/summarize-user-events index b1fa463ec9d..7a1e0ba123d 100755 --- a/bin/summarize-user-events +++ b/bin/summarize-user-events @@ -28,12 +28,9 @@ class SummarizeUserEvents end def run - results = cloudwatch_client.fetch( - query: query, - from: from_date, - to: to_date, - ) - pp results + find_cloudwatch_events do |cloudwatch_event| + pp cloudwatch_event + end end @@ -46,6 +43,7 @@ class SummarizeUserEvents , @timestamp | filter properties.user_id = '#{uuid}' | sort @timestamp asc + | limit 10000 QUERY end @@ -57,6 +55,32 @@ class SummarizeUserEvents log_group_name: 'prod_/srv/idp/shared/log/events.log', ) end + + def find_cloudwatch_events(&block) + if $stdin.tty? + cloudwatch_source(&block) + else + warn "Reading Cloudwatch events as newline-delimited JSON (ndjson) from stdin" + stdin_source(&block) + end + end + + def stdin_source(&block) + $stdin.each_line do |line| + next if line.blank? + event = JSON.parse(line) + block.call(event) + end + end + + def cloudwatch_source(&block) + cloudwatch_client.fetch( + query: query, + from: from_date, + to: to_date, + &block + ) + end end