diff --git a/README.md b/README.md index a0a307e0..e3fdf05a 100644 --- a/README.md +++ b/README.md @@ -166,6 +166,13 @@ The `--prebuiltDirectory` flag is useful for working with Webpack for example. I ## Handling `npm link` and Dependencies With Local Paths Perhaps the easiest way to handle these cases is to bundle the code using Webpack and use the `--prebuiltDirectory` flag to package the output for deployment. +## ScheduleEvents +#### Optional Parameter +When using the eventSourceFile flag (-S or --eventSourceFile) to set a ScheduleEvent trigger, you can pass an optional _ScheduleDescription_ key into the ScheduleEvent object with a custom description for the CloudWatch event rule you are defining. By default, node-lambda generates a _ScheduleDescription_ for you based on the ScheduleName and ScheduleExpression of the rule. + +#### Note on ScheduleState for ScheduleEvents +When setting ScheduleState to `ENABLED` or `DISABLED` for ScheduleEvents, it is useful to note that this sets the state of the CloudWatch Event rule but _DOES NOT_ set the state of the trigger for the Lambda function you are deploying; ScheduleEvent triggers are enabled by default in the Lambda console when added using the eventSourceFile flag. + ## Other AWS Lambda Tools Projects + [lambdaws](https://github.com/mentum/lambdaws) diff --git a/lib/schedule_events.js b/lib/schedule_events.js index 25e6be85..a204a04e 100644 --- a/lib/schedule_events.js +++ b/lib/schedule_events.js @@ -12,7 +12,11 @@ const ScheduleEvents = function(aws) { ScheduleEvents.prototype = { _ruleDescription: (params) => { - return `${params.ScheduleName} - ${params.ScheduleExpression}`; + if ('ScheduleDescription' in params && params.ScheduleDescription != null) { + return `${params.ScheduleDescription}`; + } else { + return `${params.ScheduleName} - ${params.ScheduleExpression}`; + } }, _functionName: (params) => { diff --git a/test/main.js b/test/main.js index ff9b2014..fbccb4c0 100644 --- a/test/main.js +++ b/test/main.js @@ -647,7 +647,7 @@ describe('node-lambda', function () { ScheduleEvents: [{ ScheduleName: 'node-lambda-test-schedule', ScheduleState: 'ENABLED', - ScheduleExpression: 'rate(1 hour)', + ScheduleExpression: 'rate(1 hour)' }], }; assert.deepEqual(lambda._eventSourceList(program), expected); @@ -691,6 +691,7 @@ describe('node-lambda', function () { ScheduleName: 'node-lambda-test-schedule', ScheduleState: 'ENABLED', ScheduleExpression: 'rate(1 hour)', + ScheduleDescription: 'Run node-lambda-test-function once per hour' }] }; diff --git a/test/schedule_events.js b/test/schedule_events.js index 0a1b784a..1f5d2e84 100644 --- a/test/schedule_events.js +++ b/test/schedule_events.js @@ -10,7 +10,8 @@ const params = { FunctionArn: 'arn:aws:lambda:us-west-2:XXX:function:node-lambda-test-function', ScheduleName: 'node-lambda-test-schedule', ScheduleState: 'ENABLED', - ScheduleExpression: 'rate(1 hour)' + ScheduleExpression: 'rate(1 hour)', + ScheduleDescription: null }; const mockResponse = { @@ -52,7 +53,7 @@ describe('schedule_events', () => { schedule = new ScheduleEvents(require('aws-sdk')); }); - describe('_ruleDescription', () => { + describe('_ruleDescription (default)', () => { it('correct value', () => { assert.equal( schedule._ruleDescription(params), @@ -61,6 +62,23 @@ describe('schedule_events', () => { }); }); + describe('_ruleDescription (custom)', () => { + before(() => { + params.ScheduleDescription = 'Run node-lambda-test-function once per hour'; + }); + + after(() => { + params.ScheduleDescription = null; + }); + + it('correct value', () => { + assert.equal( + schedule._ruleDescription(params), + 'Run node-lambda-test-function once per hour' + ); + }); + }); + describe('_functionName', () => { it('correct value', () => { assert.equal(