Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DeviaVir I added this subsection to the ScheduleEvents section because I feel this behavior deserves to be noted as it may be confusing to someone trying to deploy a Lambda with a disabled trigger. I wanted to bring it to your attention because I'm not certain if this is the intended behavior, but I can confirm that this is, in fact, how it currently works.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not exactly how we like it, but long as it's been documented I think we're in a better state than before already. Thanks for that!

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)
Expand Down
6 changes: 5 additions & 1 deletion lib/schedule_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
3 changes: 2 additions & 1 deletion test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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'
}]
};

Expand Down
22 changes: 20 additions & 2 deletions test/schedule_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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),
Expand All @@ -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(
Expand Down