diff --git a/lib/main.js b/lib/main.js index 8a3e510e..91251ba7 100644 --- a/lib/main.js +++ b/lib/main.js @@ -615,21 +615,26 @@ Lambda.prototype._updateEventSources = function (lambda, functionName, existingE }) } -Lambda.prototype._updateScheduleEvents = function (scheduleEvents, functionArn, scheduleList, cb) { +Lambda.prototype._updateScheduleEvents = (scheduleEvents, functionArn, scheduleList, cb) => { if (scheduleList == null) { return cb(null, []) } - return async.series(scheduleList.map(function (schedule) { - return function (_cb) { - const params = Object.assign(schedule, { FunctionArn: functionArn }) - scheduleEvents.add(params).then(function (data) { - _cb(null, params) - }).catch(function (err) { - _cb(err) - }) - } - }), function (err, results) { - cb(err, results) + + const paramsList = scheduleList.map((schedule) => + Object.assign(schedule, { FunctionArn: functionArn })) + + // series + paramsList.map((params) => { + return scheduleEvents.add(params) + }).reduce((a, b) => { + return a.then(b) + }, Promise.resolve()).then(() => { + // Since `scheduleEvents.add(params)` returns only `{}` if it succeeds + // it is not very meaningful. + // Therefore, return the params used for execution + cb(null, paramsList) + }).catch((err) => { + cb(err) }) } diff --git a/test/main.js b/test/main.js index 9d2ae9e5..83347fbe 100644 --- a/test/main.js +++ b/test/main.js @@ -807,7 +807,7 @@ describe('lib/main', function () { }) }).then(function (actual) { const expected = { - err: undefined, + err: null, results: [Object.assign( eventSourcesJsonValue.ScheduleEvents[0], { FunctionArn: functionArn }