diff --git a/lib/main.js b/lib/main.js index f51e341f..d2f2dbeb 100644 --- a/lib/main.js +++ b/lib/main.js @@ -805,35 +805,7 @@ Lambda.prototype._deployToRegion = function (program, params, region) { // Checking function return lambda.getFunction({ 'FunctionName': params.FunctionName - }, (err) => { - if (err) { - // Function does not exist - return _this._uploadNew(lambda, params).then((results) => { - console.log('=> Zip file(s) done uploading. Results follow: ') - console.log(results) - - return Promise.all([ - _this._updateEventSources( - lambda, - params.FunctionName, - [], - eventSourceList.EventSourceMappings - ), - _this._updateScheduleEvents( - scheduleEvents, - results.FunctionArn, - eventSourceList.ScheduleEvents - ) - ]).then((results) => { - resolve(results) - }).catch((err) => { - reject(err) - }) - }).catch((err) => { - reject(err) - }) - } - + }).promise().then(() => { // Function exists _this._listEventSourceMappings(lambda, { 'FunctionName': params.FunctionName @@ -862,6 +834,32 @@ Lambda.prototype._deployToRegion = function (program, params, region) { reject(err) }) }) + }).catch(() => { + // Function does not exist + return _this._uploadNew(lambda, params).then((results) => { + console.log('=> Zip file(s) done uploading. Results follow: ') + console.log(results) + + return Promise.all([ + _this._updateEventSources( + lambda, + params.FunctionName, + [], + eventSourceList.EventSourceMappings + ), + _this._updateScheduleEvents( + scheduleEvents, + results.FunctionArn, + eventSourceList.ScheduleEvents + ) + ]).then((results) => { + resolve(results) + }).catch((err) => { + reject(err) + }) + }).catch((err) => { + reject(err) + }) }) }) }