Skip to content

Instantly share code, notes, and snippets.

@aackerman
Last active December 7, 2016 19:51
Show Gist options
  • Save aackerman/a5d0a813aa3cc7fd36b48d63ad82afa2 to your computer and use it in GitHub Desktop.
Save aackerman/a5d0a813aa3cc7fd36b48d63ad82afa2 to your computer and use it in GitHub Desktop.
Cloudwatch Tail logs
var AWS = require('aws-sdk');
AWS.config.region = 'us-east-1'
var service = new AWS.CloudWatchLogs();
function getLogs(params) {
params = Object.assign({}, params, { endTime: new Date().getTime() - 30000 })
service.getLogEvents(p, function(err, data) {
if (err) { console.log(err) }
if (data && data.events && data.events.length !== 0) {
data.events.forEach(function(event) {
console.log(new Date(event.timestamp) + ' : ' + event.message)
})
}
let nextParams = Object.assign({}, p, {
startTime: undefined,
nextToken: data.nextForwardToken
})
setTimeout(getLogs, 1000, nextParams)
})
}
let logGroupName = process.argv[2]
let logStreamName = process.argv[3]
if (!logGroupName || !logStreamName) {
return console.error('Usage: node cloudtail.js LogGroupName LogStreamName')
}
getLogs({
logGroupName: logGroupName,
logStreamName: logStreamName,
startFromHead: false
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment