Last active
February 12, 2018 12:34
-
-
Save ro-tex/2707a4cd10853ec84041057e7e7855eb to your computer and use it in GitHub Desktop.
Downloads all CloudWatch logs for a given lambda that have the given prefix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
if (!ARGV[0] || !ARGV[1]) | |
puts "Usage: $ ruby getCloudWatchLogs.rb [log group name, e.g. /aws/lambda/myLambda] [log stream prefix, e.g. 2018/02/01/[123]]" | |
exit | |
end | |
logGroupName = ARGV[0] | |
logStreamPrefix = ARGV[1] | |
logStreams = JSON.parse(`aws logs describe-log-streams --log-group-name #{logGroupName} --log-stream-name-prefix #{logStreamPrefix}`) | |
logStreams["logStreams"].map{|log| log["logStreamName"]}.each{|logname| | |
output = JSON.parse(`aws logs get-log-events --log-group-name /aws/lambda/StereotypeLambda --log-stream-name #{logname}`) | |
File.open("./#{logname.gsub(/\//, "_")}","w") do |f| | |
output["events"].each{|e| f.write(e['message'])} | |
end | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment