For one of our Software as a Service as a Service (SaaSaaS) clients, we built a serverless Lambda service and charged them per successful invocation. Each time the service succeeds, we charge; therefore, we wanted to figure out how many times it was successful in order to calculate their bill. Our service logs the text “Posting response” if the invocation was successful; if you want to get a total invocation count, in the steps below, replace “Posting response” with “END RequestId”.
- Follow these instructions to export your log data to an S3 bucket under your control: https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/S3ExportTasksConsole.html
-
Run this on your local commandline: aws s3 cp s3://bucket-with-the-export/exportedlogs lambda-exported-logs –recursive
- Run this on the local commandline to uncompress all the logs: gunzip -r lambda-exported-logs
- Install The Silver Searcher, a super-fast grep-like tool available on most platforms
-
Fire up the ruby interpreter (type irb on your local commandline) and run this code:
irb(main)> res=`
ag -c "Posting response"
`
irb(main)> res.split(“\n”).map{|x|x.split(‘:’)[-1]}.map(&:to_i).inject(:+) - You’ll get your total invocation count.