UNPKG

lambee

Version:

A tool to help developer work with AWS Lambda.

37 lines (30 loc) 1.15 kB
const AWS = require('aws-sdk') /** * Make the call to AWS CloudWatch to get the logs. * * @param string fnName The name of the Lambda function. * @param number startTime The start of the time range, expressed as the number * of milliseconds after Jan 1, 1970 00:00:00 UTC. Events with a timestamp * before this time are not returned. * @param number endTime The end of the time range, expressed as the number of * milliseconds after Jan 1, 1970 00:00:00 UTC. Events with a timestamp later * than this time are not returned. */ async function getLogs(fnName, startTime, endTime, awsRegion, awsProfile, debug) { const cwlogs = new AWS.CloudWatchLogs({ apiVersion: '2014-03-28', region: awsRegion, credentials: awsProfile ? new AWS.SharedIniFileCredentials({profile: awsProfile}) : undefined }) debug && console.debug('AWS Config', cwlogs.config) const params = { logGroupName: `/aws/lambda/${fnName}`, startTime, endTime } debug && console.debug('filterLogEvents', params) return cwlogs.filterLogEvents(params).promise() } module.exports = { getLogs }