diff --git a/lib/main.js b/lib/main.js index bde0a895..c10751a8 100644 --- a/lib/main.js +++ b/lib/main.js @@ -567,13 +567,15 @@ Lambda.prototype._buildAndArchive = function (program, archiveCallback) { }) } -Lambda.prototype._listEventSourceMappings = function (lambda, params, cb) { - return lambda.listEventSourceMappings(params, function (err, data) { - var eventSourceMappings = [] - if (!err && data && data.EventSourceMappings) { - eventSourceMappings = data.EventSourceMappings - } - return cb(err, eventSourceMappings) +Lambda.prototype._listEventSourceMappings = (lambda, params) => { + return new Promise((resolve, reject) => { + lambda.listEventSourceMappings(params, (err, data) => { + if (err) return reject(err) + if (data && data.EventSourceMappings) { + return resolve(data.EventSourceMappings) + } + return resolve([]) + }) }) } @@ -768,11 +770,9 @@ Lambda.prototype._deployToRegion = function (program, params, region) { 'FunctionName': params.FunctionName }).promise().then(() => { // Function exists - _this._listEventSourceMappings(lambda, { + return _this._listEventSourceMappings(lambda, { 'FunctionName': params.FunctionName - }, (err, existingEventSourceList) => { - if (err) return reject(err) - + }).then((existingEventSourceList) => { return Promise.all([ _this._uploadExisting(lambda, params).then((results) => { console.log('=> Zip file(s) done uploading. Results follow: ') @@ -791,9 +791,9 @@ Lambda.prototype._deployToRegion = function (program, params, region) { ) ]).then((results) => { resolve(results) - }).catch((err) => { - reject(err) }) + }).catch((err) => { + reject(err) }) }).catch(() => { // Function does not exist @@ -815,8 +815,6 @@ Lambda.prototype._deployToRegion = function (program, params, region) { ) ]).then((results) => { resolve(results) - }).catch((err) => { - reject(err) }) }).catch((err) => { reject(err) diff --git a/test/main.js b/test/main.js index 4314d992..5c51f4f7 100644 --- a/test/main.js +++ b/test/main.js @@ -800,6 +800,20 @@ describe('lib/main', function () { }) }) + describe('_listEventSourceMappings', () => { + it('simple test with mock', () => { + return lambda._listEventSourceMappings( + awsLambda, + { FunctionName: 'test-func' } + ).then((results) => { + assert.deepEqual( + results, + lambdaMockSettings.listEventSourceMappings.EventSourceMappings + ) + }) + }) + }) + describe('_updateEventSources', () => { const eventSourcesJsonValue = { EventSourceMappings: [{