Skip to content

Commit 28bb53f

Browse files
abetomoDeviaVir
authored andcommitted
Added the ability to set constants when scheduling a Lambda function Cloudwatch event. (#380)
* Added the ability to set constants when scheduling a Lambda function Cloudwatch event. * Remove unnecessary space * Modify example JSON key name * Set default value when key does not exist * Update unit test
1 parent 812cef9 commit 28bb53f

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

lib/event_sources.json.example

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111
{
1212
"ScheduleName": "node-lambda-test-schedule",
1313
"ScheduleState": "ENABLED",
14-
"ScheduleExpression": "rate(1 hour)"
14+
"ScheduleExpression": "rate(1 hour)",
15+
"Input":
16+
{
17+
"key1": "value",
18+
"key2": "value"
19+
}
1520
}
1621
]
1722
}

lib/schedule_events.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ class ScheduleEvents {
7171
Rule: params.ScheduleName,
7272
Targets: [{
7373
Arn: params.FunctionArn,
74-
Id: this._functionName(params)
74+
Id: this._functionName(params),
75+
Input: params.hasOwnProperty('Input') ? JSON.stringify(params.Input) : ''
7576
}]
7677
}
7778
}

test/main.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,11 @@ describe('lib/main', function () {
840840
ScheduleEvents: [{
841841
ScheduleName: 'node-lambda-test-schedule',
842842
ScheduleState: 'ENABLED',
843-
ScheduleExpression: 'rate(1 hour)'
843+
ScheduleExpression: 'rate(1 hour)',
844+
Input: {
845+
key1: 'value',
846+
key2: 'value'
847+
}
844848
}]
845849
}
846850
assert.deepEqual(lambda._eventSourceList(program), expected)

test/schedule_events.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,32 @@ describe('lib/schedule_events', () => {
121121
})
122122

123123
describe('_putTargetsParams', () => {
124-
it('correct value', () => {
124+
it('correct value (No "Input" setting)', () => {
125125
const expected = {
126126
Rule: 'node-lambda-test-schedule',
127127
Targets: [{
128128
Arn: 'arn:aws:lambda:us-west-2:XXX:function:node-lambda-test-function',
129-
Id: 'node-lambda-test-function'
129+
Id: 'node-lambda-test-function',
130+
Input: ''
130131
}]
131132
}
132133
assert.deepEqual(schedule._putTargetsParams(params), expected)
133134
})
135+
136+
it('correct value ("Input" setting)', () => {
137+
const expected = {
138+
Rule: 'node-lambda-test-schedule',
139+
Targets: [{
140+
Arn: 'arn:aws:lambda:us-west-2:XXX:function:node-lambda-test-function',
141+
Id: 'node-lambda-test-function',
142+
Input: '{"key":"value"}'
143+
}]
144+
}
145+
assert.deepEqual(
146+
schedule._putTargetsParams(Object.assign({Input: {key: 'value'}}, params)),
147+
expected
148+
)
149+
})
134150
})
135151

136152
describe('_putRule', () => {

0 commit comments

Comments
 (0)