lambee
Version:
A tool to help developer work with AWS Lambda.
33 lines (27 loc) • 1.76 kB
JavaScript
const getLogs = require('./getLogs')
/**
* Registers this CLI action with Commander.
*
* @param {*} program An instance of Commander CLI library
*/
function registerAction(program) {
program
.command('fnlogs <functionName>')
.description('Prints nice clean logs for a Lambda function.')
.option('-s, --startTime [startTime]', 'Start time eg "10 mins ago"')
.option('-e, --endTime <endTime>', 'End time eg "5 mins ago"')
.option('-l, --logLevel <logLevel>', '1: All, 2: DEBUG (default), 3: INFO, 4: ERROR')
.option('-p, --profile [profile]', 'The AWS profile. You can set this using environment variable AWS_PROFILE.')
.option('-r, --region <region>', 'The AWS region. You can set this using environment variable AWS_DEFAULT_REGION.')
.option('-c, --cache', 'Cache results locally. Makes repeated execution much quicker on slow networks. Will not pick up changes to the logs though.')
.option('--debug', 'Enable debug logging')
.action((functionName, cmdObj) => {
const profile = cmdObj.profile || process.env.AWS_PROFILE
const region = cmdObj.region || process.env.AWS_DEFAULT_REGION
const logLevel = parseInt(cmdObj.logLevel) ? parseInt(cmdObj.logLevel) : 2
if (!profile) return console.error('AWS profile not set. Use --profile option or AWS_PROFILE environment variable.')
if (!region) return console.error('AWS region not set. Use --region option or AWS_DEFAULT_REGION environment variable.')
getLogs(functionName, cmdObj.startTime, cmdObj.endTime, logLevel, cmdObj.cache, profile, region, cmdObj.debug).then(console.log).catch(console.log)
})
}
module.exports = { registerAction }