Saturday, March 4, 2017

AWS Powershell Tools Snippets: CodeBuild Cloudwatch Logs

We've been using AWS CodeBuild to run java maven builds almost since it came out. It's great when it works, but when Maven has a problem it can pretty pretty difficult to sift through logs in the Cloudwatch console.


Below is an AWS Powershell Tools snippet that will pull down a cloudwatch log stream and dump it both to your console and to a file. There are a few parameters you'll need to set


  1. LogStreamName - this should be the specific log stream you want to download. Usually this correlates to a Codebuild run
  2. LogGroupName - this will be the /aws/codebuild/<your project name>
  3. OutFile location - this is where you want the files dumped

Get-CWLLogEvents -logstreamname logstreamname -loggroupname /aws/codebuild/yourprojectname).events | foreach {$message = "$($_.TimeStamp) - $($_.Message)";write-host $message; $message | out-file logfilelocation.log -append}

This command can also be used to pull down other log streams as well, you just need to swap out the same variables.

Happy troubleshooting!

No comments:

Post a Comment