From 594861e73f8fbb7e2e99e70ec8d2373981e94fc9 Mon Sep 17 00:00:00 2001 From: abetomo Date: Tue, 11 Apr 2017 15:21:39 +0900 Subject: [PATCH 01/12] Fix to use authenticated `aws` object in main.js --- lib/schedule_events.js | 56 +++++++++++++++++++++++------------------ test/schedule_events.js | 3 ++- 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/lib/schedule_events.js b/lib/schedule_events.js index 116fb4c7..c24f8ce9 100644 --- a/lib/schedule_events.js +++ b/lib/schedule_events.js @@ -1,14 +1,16 @@ 'use strict'; -const aws = require('aws-sdk'); -const lambda = new aws.Lambda({ - apiVersion: '2015-03-31' -}); -const cloudwatchevents = new aws.CloudWatchEvents({ - apiVersion: '2015-10-07' -}); +const ScheduleEvents = function(aws) { + // Authenticated `aws` object in `lib/main.js` + this.lambda = new aws.Lambda({ + apiVersion: '2015-03-31' + }); + this.cloudwatchevents = new aws.CloudWatchEvents({ + apiVersion: '2015-10-07' + }); +}; -const ScheduleEvents = { +ScheduleEvents.prototype = { _ruleDescription: (params) => { return `${params.ScheduleName} - ${params.ScheduleExpression}`; }, @@ -17,20 +19,21 @@ const ScheduleEvents = { return params.FunctionArnPrefix + params.FunctionName; }, - _putRulePrams: (params) => { + _putRulePrams: function(params) { return { Name: params.ScheduleName, - Description: ScheduleEvents._ruleDescription(params), + Description: this._ruleDescription(params), State: params.ScheduleState, ScheduleExpression: params.ScheduleExpression }; }, - _putRule: (params) => { + _putRule: function(params) { + const _this = this; // return RuleArn if created return new Promise((resolve) => { - const _params = ScheduleEvents._putRulePrams(params); - cloudwatchevents.putRule(_params, (err, rule) => { + const _params = _this._putRulePrams(params); + _this.cloudwatchevents.putRule(_params, (err, rule) => { if (err) throw err; resolve(rule); }); @@ -47,10 +50,11 @@ const ScheduleEvents = { }; }, - _addPermission: (params) => { + _addPermission: function(params) { + const _this = this; return new Promise((resolve) => { - const _params = ScheduleEvents._addPermissionParams(params); - lambda.addPermission(_params, (err, data) => { + const _params = _this._addPermissionParams(params); + _this.lambda.addPermission(_params, (err, data) => { if (err) { if (err.code != 'ResourceConflictException') throw err; // If it exists it will result in an error but there is no problem. @@ -61,20 +65,21 @@ const ScheduleEvents = { }); }, - _putTargetsParams: (params) => { + _putTargetsParams: function(params) { return { Rule: params.ScheduleName, Targets: [{ - Arn: ScheduleEvents._functionArn(params), + Arn: this._functionArn(params), Id: params.FunctionName }] }; }, - _putTargets: (params) => { + _putTargets: function(params) { + const _this = this; return new Promise((resolve) => { - const _params = ScheduleEvents._putTargetsParams(params); - cloudwatchevents.putTargets(_params, (err, data) => { + const _params = _this._putTargetsParams(params); + _this.cloudwatchevents.putTargets(_params, (err, data) => { // even if it is already registered, it will not be an error. if (err) throw(err); resolve(data); @@ -82,13 +87,14 @@ const ScheduleEvents = { }); }, - add: (params) => { + add: function(params) { + const _this = this; return Promise.resolve().then(() => { - return ScheduleEvents._putRule(params); + return _this._putRule(params); }).then((rule) => { - return ScheduleEvents._addPermission(Object.assign(params, rule)); + return _this._addPermission(Object.assign(params, rule)); }).then((data) => { - return ScheduleEvents._putTargets(params); + return _this._putTargets(params); }); }, }; diff --git a/test/schedule_events.js b/test/schedule_events.js index 0f1df1ed..001f9b1a 100644 --- a/test/schedule_events.js +++ b/test/schedule_events.js @@ -4,6 +4,7 @@ const assert = require('chai').assert; const path = require('path'); const aws = require('aws-sdk-mock'); aws.setSDK(path.resolve('node_modules/aws-sdk')); +const ScheduleEvents = require(path.join('..', 'lib', 'schedule_events')); const params = { FunctionName: 'node-lambda-test-function', @@ -49,7 +50,7 @@ describe('schedule_events', () => { callback(null, mockResponse.addPermission); }); - schedule = require(path.join('..', 'lib', 'schedule_events')); + schedule = new ScheduleEvents(require('aws-sdk')); }); describe('_ruleDescription', () => { From 332e780b1bbed8efb5f1ea7c38f6c08f8babf268 Mon Sep 17 00:00:00 2001 From: abetomo Date: Tue, 11 Apr 2017 17:31:41 +0900 Subject: [PATCH 02/12] Fix to enable ScheduleEvents to be specified in event_sources.json --- lib/event_sources.json.example | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/event_sources.json.example b/lib/event_sources.json.example index 8944af9f..6e774869 100644 --- a/lib/event_sources.json.example +++ b/lib/event_sources.json.example @@ -1,8 +1,18 @@ -[ +{ + "EventSourceMappings": [ { - "EventSourceArn": "your event source arn", - "StartingPosition": "LATEST", - "BatchSize": 100, - "Enabled": true + "EventSourceArn": "your event source arn", + "StartingPosition": "LATEST", + "BatchSize": 100, + "Enabled": true } -] \ No newline at end of file + ], + "ScheduleEvents": [ + { + "FunctionArnPrefix": "arn:aws:lambda:us-west-2:XXX:function:", + "ScheduleName": "node-lambda-test-schedule", + "ScheduleState": "ENABLED", + "ScheduleExpression": "rate(1 hour)" + } + ] +} From f276d8d5764cfabd8c05058d9a60f1c964b172ec Mon Sep 17 00:00:00 2001 From: abetomo Date: Tue, 11 Apr 2017 17:42:40 +0900 Subject: [PATCH 03/12] Supports new event_sources.json format --- lib/main.js | 26 ++++++++++++---- test/main.js | 88 +++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 97 insertions(+), 17 deletions(-) diff --git a/lib/main.js b/lib/main.js index 9ddfeb41..0687a059 100644 --- a/lib/main.js +++ b/lib/main.js @@ -147,11 +147,25 @@ Lambda.prototype._eventSourceList = function (program) { if (!program.eventSourceFile) { return []; } - try { - return fs.readJsonSync(program.eventSourceFile); - } catch(err) { - throw err; + const list = (function() { + try { + return fs.readJsonSync(program.eventSourceFile); + } catch(err) { + throw err; + } + })(); + + if (Object.prototype.toString.call(list) === '[object Array]') { + // backward-compatible + return { EventSourceMappings: list }; + } + if (!list.EventSourceMappings) { + list.EventSourceMappings = []; + } + if (!list.ScheduleEvents) { + list.ScheduleEvents = []; } + return list; }; /** @@ -607,7 +621,7 @@ Lambda.prototype.deploy = function (program) { console.log(results); // Updating event source(s) - _this._updateEventSources(lambda, params.FunctionName, [], eventSourceList, function(err, results) { + _this._updateEventSources(lambda, params.FunctionName, [], eventSourceList.EventSourceMappings, function(err, results) { cb(null, results); }); }); @@ -632,7 +646,7 @@ Lambda.prototype.deploy = function (program) { }); }, function(_callback) { - _this._updateEventSources(lambda, params.FunctionName, existingEventSourceList, eventSourceList, function(err, results) { + _this._updateEventSources(lambda, params.FunctionName, existingEventSourceList, eventSourceList.EventSourceMappings, function(err, results) { _callback(err, results); }); } diff --git a/test/main.js b/test/main.js index addc05c7..cf4c5b74 100644 --- a/test/main.js +++ b/test/main.js @@ -510,17 +510,6 @@ describe('node-lambda', function () { assert.deepEqual(lambda._eventSourceList(program), []); }); - it('program.eventSourceFile is valid value', function () { - program.eventSourceFile = 'event_sources.json'; - const expected = [{ - BatchSize: 100, - Enabled: true, - EventSourceArn: 'your event source arn', - StartingPosition: 'LATEST', - }]; - assert.deepEqual(lambda._eventSourceList(program), expected); - }); - it('program.eventSourceFile is invalid value', function () { program.eventSourceFile = '/hoge/fuga'; assert.throws( @@ -529,6 +518,83 @@ describe('node-lambda', function () { "ENOENT: no such file or directory, open '/hoge/fuga'" ); }); + + describe('program.eventSourceFile is valid value', function() { + before(function () { + fs.writeFileSync('only_EventSourceMappings.json', JSON.stringify({ + EventSourceMappings: [{ test: 1 }] + })); + fs.writeFileSync('only_ScheduleEvents.json', JSON.stringify({ + ScheduleEvents: [{ test: 2 }] + })); + }); + + after(function () { + fs.unlinkSync('only_EventSourceMappings.json'); + fs.unlinkSync('only_ScheduleEvents.json'); + }); + + it('only EventSourceMappings', function () { + program.eventSourceFile = 'only_EventSourceMappings.json'; + const expected = { + EventSourceMappings: [{ test: 1 }], + ScheduleEvents: [], + }; + assert.deepEqual(lambda._eventSourceList(program), expected); + }); + + it('only ScheduleEvents', function () { + program.eventSourceFile = 'only_ScheduleEvents.json'; + const expected = { + EventSourceMappings: [], + ScheduleEvents: [{ test: 2 }], + }; + assert.deepEqual(lambda._eventSourceList(program), expected); + }); + + it('EventSourceMappings & ScheduleEvents', function () { + program.eventSourceFile = 'event_sources.json'; + const expected = { + EventSourceMappings: [{ + BatchSize: 100, + Enabled: true, + EventSourceArn: 'your event source arn', + StartingPosition: 'LATEST', + }], + ScheduleEvents: [{ + FunctionArnPrefix: 'arn:aws:lambda:us-west-2:XXX:function:', + ScheduleName: 'node-lambda-test-schedule', + ScheduleState: 'ENABLED', + ScheduleExpression: 'rate(1 hour)', + }], + }; + assert.deepEqual(lambda._eventSourceList(program), expected); + }); + }); + + describe('old style event_sources.json', function () { + const oldStyleValue = [{ + BatchSize: 100, + Enabled: true, + EventSourceArn: 'your event source arn', + StartingPosition: 'LATEST', + }]; + const fileName = 'event_sources_old_style.json'; + + before(function () { + fs.writeFileSync(fileName, JSON.stringify(oldStyleValue)); + }); + + after(function () { + fs.unlinkSync(fileName); + }); + + it('program.eventSourceFile is valid value', function () { + program.eventSourceFile = fileName; + const expected = { EventSourceMappings: oldStyleValue }; + assert.deepEqual(lambda._eventSourceList(program), expected); + }); + }); }); }); From 2436d15c0383afc7276ce5edf19e496ea714b1d6 Mon Sep 17 00:00:00 2001 From: abetomo Date: Wed, 12 Apr 2017 16:05:31 +0900 Subject: [PATCH 04/12] modify default value to new format --- lib/main.js | 5 ++++- test/main.js | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 0687a059..46df3f8a 100644 --- a/lib/main.js +++ b/lib/main.js @@ -145,7 +145,10 @@ Lambda.prototype._params = function (program, buffer) { Lambda.prototype._eventSourceList = function (program) { if (!program.eventSourceFile) { - return []; + return { + EventSourceMappings: [], + ScheduleEvents: [] + }; } const list = (function() { try { diff --git a/test/main.js b/test/main.js index cf4c5b74..1c8713cd 100644 --- a/test/main.js +++ b/test/main.js @@ -507,7 +507,10 @@ describe('node-lambda', function () { describe('_eventSourceList', function () { it('program.eventSourceFile is empty value', function () { program.eventSourceFile = ''; - assert.deepEqual(lambda._eventSourceList(program), []); + assert.deepEqual( + lambda._eventSourceList(program), + { EventSourceMappings: [], ScheduleEvents: [] } + ); }); it('program.eventSourceFile is invalid value', function () { From e3c80341cdaa3b0e90a23d8dadd5a7c016de20ec Mon Sep 17 00:00:00 2001 From: abetomo Date: Wed, 12 Apr 2017 18:24:47 +0900 Subject: [PATCH 05/12] Added import of ScheduleEvents --- lib/main.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/main.js b/lib/main.js index 46df3f8a..6d9a4e89 100644 --- a/lib/main.js +++ b/lib/main.js @@ -9,6 +9,7 @@ var path = require('path'); var async = require('async'); var zip = new require('node-zip')(); var dotenv = require('dotenv'); +var ScheduleEvents = require('./schedule_events'); var maxBufferSize = 50 * 1024 * 1024; @@ -609,6 +610,7 @@ Lambda.prototype.deploy = function (program) { var lambda = new aws.Lambda({ apiVersion: '2015-03-31' }); + var scheduleEvents = new ScheduleEvents(aws); // Checking function return lambda.getFunction({ From b7f2dba36d9b8f591c4ce01377f4744050bdac62 Mon Sep 17 00:00:00 2001 From: abetomo Date: Wed, 12 Apr 2017 18:26:13 +0900 Subject: [PATCH 06/12] Add _updateScheduleEvents function --- lib/main.js | 15 +++++++++++++ test/main.js | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/lib/main.js b/lib/main.js index 6d9a4e89..9bb9ff88 100644 --- a/lib/main.js +++ b/lib/main.js @@ -533,6 +533,21 @@ Lambda.prototype._updateEventSources = function (lambda, functionName, existingE }); }; +Lambda.prototype._updateScheduleEvents = function (scheduleEvents, functionName, scheduleList, cb) { + return async.series(scheduleList.map(function(schedule) { + return function(_cb) { + const params = Object.assign(schedule, { FunctionName: functionName }); + scheduleEvents.add(params).then(function (data) { + _cb(null, params); + }).catch(function (err) { + _cb(err); + }); + }; + }), function(err, results) { + cb(err, results); + }); +}; + Lambda.prototype.package = function (program) { var _this = this; if (!program.packageDirectory) { diff --git a/test/main.js b/test/main.js index 1c8713cd..0af3b6d5 100644 --- a/test/main.js +++ b/test/main.js @@ -601,6 +601,65 @@ describe('node-lambda', function () { }); }); + describe('_updateScheduleEvents', function () { + const aws = require('aws-sdk-mock'); + const ScheduleEvents = require('../lib/schedule_events'); + const eventSourcesJsonValue = { + ScheduleEvents: [{ + FunctionArnPrefix: 'arn:aws:lambda:us-west-2:XXX:function:', + ScheduleName: 'node-lambda-test-schedule', + ScheduleState: 'ENABLED', + ScheduleExpression: 'rate(1 hour)', + }] + }; + + var schedule = null; + + before(function () { + aws.mock('CloudWatchEvents', 'putRule', function (params, callback) { + callback(null, {}); + }); + aws.mock('CloudWatchEvents', 'putTargets', function (params, callback) { + callback(null, {}); + }); + aws.mock('Lambda', 'addPermission', function (params, callback) { + callback(null, {}); + }); + + fs.writeFileSync( + 'event_sources.json', + JSON.stringify(eventSourcesJsonValue) + ); + + schedule = new ScheduleEvents(require('aws-sdk')); + }); + + after(function () { + fs.unlinkSync('event_sources.json'); + aws.restore('CloudWatchEvents'); + aws.restore('Lambda'); + }); + + it('simple test with mock', function () { + program.eventSourceFile = 'event_sources.json'; + const eventSourceList = lambda._eventSourceList(program); + return new Promise(function (resolve) { + lambda._updateScheduleEvents(schedule, 'testfunc', eventSourceList.ScheduleEvents, function(err, results) { + resolve({ err: err, results: results }); + }); + }).then(function (actual) { + const expected = { + err: undefined, + results: [Object.assign( + eventSourcesJsonValue.ScheduleEvents[0], + { FunctionName: 'testfunc' } + )] + }; + assert.deepEqual(actual, expected); + }); + }); + }); + describe('check env vars before create sample files', function () { const filesCreatedBySetup = [ '.env', From d83843caadf069f1c42a98259a9493d5d6cb6cc1 Mon Sep 17 00:00:00 2001 From: abetomo Date: Wed, 12 Apr 2017 18:41:44 +0900 Subject: [PATCH 07/12] Add execution process of _updateScheduleEvents --- lib/main.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index 9bb9ff88..1de40555 100644 --- a/lib/main.js +++ b/lib/main.js @@ -640,9 +640,20 @@ Lambda.prototype.deploy = function (program) { console.log('=> Zip file(s) done uploading. Results follow: '); console.log(results); - // Updating event source(s) - _this._updateEventSources(lambda, params.FunctionName, [], eventSourceList.EventSourceMappings, function(err, results) { - cb(null, results); + async.parallel([ + function(_callback) { + // Updating event source(s) + _this._updateEventSources(lambda, params.FunctionName, [], eventSourceList.EventSourceMappings, function(err, results) { + _callback(null, results); + }); + }, + function(_callback) { + _this._updateScheduleEvents(scheduleEvents, params.FunctionName, eventSourceList.ScheduleEvents, function(err, results) { + _callback(err, results); + }); + } + ], function(err, results) { + cb(err, results); }); }); } @@ -669,6 +680,11 @@ Lambda.prototype.deploy = function (program) { _this._updateEventSources(lambda, params.FunctionName, existingEventSourceList, eventSourceList.EventSourceMappings, function(err, results) { _callback(err, results); }); + }, + function(_callback) { + _this._updateScheduleEvents(scheduleEvents, params.FunctionName, eventSourceList.ScheduleEvents, function(err, results) { + _callback(err, results); + }); } ], function(err, results) { cb(err, results); From 572ba7356d3ce70aa3e0f6dea83deec466d11718 Mon Sep 17 00:00:00 2001 From: abetomo Date: Wed, 12 Apr 2017 18:59:24 +0900 Subject: [PATCH 08/12] Improve log output Improved to be displayed as `[[[null], [[Object], [Object]]]]` --- lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index 1de40555..1dad38fe 100644 --- a/lib/main.js +++ b/lib/main.js @@ -696,7 +696,7 @@ Lambda.prototype.deploy = function (program) { throw err; } console.log('=> All tasks done. Results follow: '); - console.log(results); + console.log(JSON.stringify(results, null, ' ')); }); }); }; From f8c8cb3c72adf25531b12a811323cbbd7d6c03a6 Mon Sep 17 00:00:00 2001 From: abetomo Date: Thu, 13 Apr 2017 11:35:11 +0900 Subject: [PATCH 09/12] Fix parameters to `FunctionArn` --- lib/schedule_events.js | 12 ++++++------ test/schedule_events.js | 9 ++++----- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/schedule_events.js b/lib/schedule_events.js index c24f8ce9..25e6be85 100644 --- a/lib/schedule_events.js +++ b/lib/schedule_events.js @@ -15,8 +15,8 @@ ScheduleEvents.prototype = { return `${params.ScheduleName} - ${params.ScheduleExpression}`; }, - _functionArn: (params) => { - return params.FunctionArnPrefix + params.FunctionName; + _functionName: (params) => { + return params.FunctionArn.split(':').pop(); }, _putRulePrams: function(params) { @@ -40,10 +40,10 @@ ScheduleEvents.prototype = { }); }, - _addPermissionParams: (params) => { + _addPermissionParams: function(params) { return { Action: 'lambda:InvokeFunction', - FunctionName: params.FunctionName, + FunctionName: this._functionName(params), Principal: 'events.amazonaws.com', SourceArn: params.RuleArn, StatementId: params.ScheduleName @@ -69,8 +69,8 @@ ScheduleEvents.prototype = { return { Rule: params.ScheduleName, Targets: [{ - Arn: this._functionArn(params), - Id: params.FunctionName + Arn: params.FunctionArn, + Id: this._functionName(params) }] }; }, diff --git a/test/schedule_events.js b/test/schedule_events.js index 001f9b1a..0a1b784a 100644 --- a/test/schedule_events.js +++ b/test/schedule_events.js @@ -7,8 +7,7 @@ aws.setSDK(path.resolve('node_modules/aws-sdk')); const ScheduleEvents = require(path.join('..', 'lib', 'schedule_events')); const params = { - FunctionName: 'node-lambda-test-function', - FunctionArnPrefix: 'arn:aws:lambda:us-west-2:XXX:function:', + FunctionArn: 'arn:aws:lambda:us-west-2:XXX:function:node-lambda-test-function', ScheduleName: 'node-lambda-test-schedule', ScheduleState: 'ENABLED', ScheduleExpression: 'rate(1 hour)' @@ -62,11 +61,11 @@ describe('schedule_events', () => { }); }); - describe('_functionArn', () => { + describe('_functionName', () => { it('correct value', () => { assert.equal( - schedule._functionArn(params), - 'arn:aws:lambda:us-west-2:XXX:function:node-lambda-test-function' + schedule._functionName(params), + 'node-lambda-test-function' ); }); }); From b923b5e044c389ba58eaeca8431b668501c8b4d8 Mon Sep 17 00:00:00 2001 From: abetomo Date: Thu, 13 Apr 2017 11:39:09 +0900 Subject: [PATCH 10/12] Remove unnecessary key --- lib/event_sources.json.example | 1 - test/main.js | 1 - 2 files changed, 2 deletions(-) diff --git a/lib/event_sources.json.example b/lib/event_sources.json.example index 6e774869..1b2d7936 100644 --- a/lib/event_sources.json.example +++ b/lib/event_sources.json.example @@ -9,7 +9,6 @@ ], "ScheduleEvents": [ { - "FunctionArnPrefix": "arn:aws:lambda:us-west-2:XXX:function:", "ScheduleName": "node-lambda-test-schedule", "ScheduleState": "ENABLED", "ScheduleExpression": "rate(1 hour)" diff --git a/test/main.js b/test/main.js index 0af3b6d5..3869ed8f 100644 --- a/test/main.js +++ b/test/main.js @@ -565,7 +565,6 @@ describe('node-lambda', function () { StartingPosition: 'LATEST', }], ScheduleEvents: [{ - FunctionArnPrefix: 'arn:aws:lambda:us-west-2:XXX:function:', ScheduleName: 'node-lambda-test-schedule', ScheduleState: 'ENABLED', ScheduleExpression: 'rate(1 hour)', From d5ffb8ad97c250870b1432d90223cb8a67f3391c Mon Sep 17 00:00:00 2001 From: abetomo Date: Thu, 13 Apr 2017 11:40:21 +0900 Subject: [PATCH 11/12] Fix as argument changed from functionName to functionArn --- lib/main.js | 15 ++++++--------- test/main.js | 6 +++--- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/lib/main.js b/lib/main.js index 1dad38fe..51d6a987 100644 --- a/lib/main.js +++ b/lib/main.js @@ -533,10 +533,10 @@ Lambda.prototype._updateEventSources = function (lambda, functionName, existingE }); }; -Lambda.prototype._updateScheduleEvents = function (scheduleEvents, functionName, scheduleList, cb) { +Lambda.prototype._updateScheduleEvents = function (scheduleEvents, functionArn, scheduleList, cb) { return async.series(scheduleList.map(function(schedule) { return function(_cb) { - const params = Object.assign(schedule, { FunctionName: functionName }); + const params = Object.assign(schedule, { FunctionArn: functionArn }); scheduleEvents.add(params).then(function (data) { _cb(null, params); }).catch(function (err) { @@ -648,7 +648,7 @@ Lambda.prototype.deploy = function (program) { }); }, function(_callback) { - _this._updateScheduleEvents(scheduleEvents, params.FunctionName, eventSourceList.ScheduleEvents, function(err, results) { + _this._updateScheduleEvents(scheduleEvents, results.FunctionArn, eventSourceList.ScheduleEvents, function(err, results) { _callback(err, results); }); } @@ -673,7 +673,9 @@ Lambda.prototype.deploy = function (program) { } console.log('=> Zip file(s) done uploading. Results follow: '); console.log(results); - _callback(err, results); + _this._updateScheduleEvents(scheduleEvents, results.FunctionArn, eventSourceList.ScheduleEvents, function(err, results) { + _callback(err, results); + }); }); }, function(_callback) { @@ -681,11 +683,6 @@ Lambda.prototype.deploy = function (program) { _callback(err, results); }); }, - function(_callback) { - _this._updateScheduleEvents(scheduleEvents, params.FunctionName, eventSourceList.ScheduleEvents, function(err, results) { - _callback(err, results); - }); - } ], function(err, results) { cb(err, results); }); diff --git a/test/main.js b/test/main.js index 3869ed8f..883bf23b 100644 --- a/test/main.js +++ b/test/main.js @@ -605,7 +605,6 @@ describe('node-lambda', function () { const ScheduleEvents = require('../lib/schedule_events'); const eventSourcesJsonValue = { ScheduleEvents: [{ - FunctionArnPrefix: 'arn:aws:lambda:us-west-2:XXX:function:', ScheduleName: 'node-lambda-test-schedule', ScheduleState: 'ENABLED', ScheduleExpression: 'rate(1 hour)', @@ -642,8 +641,9 @@ describe('node-lambda', function () { it('simple test with mock', function () { program.eventSourceFile = 'event_sources.json'; const eventSourceList = lambda._eventSourceList(program); + const functionArn = 'arn:aws:lambda:us-west-2:XXX:function:node-lambda-test-function'; return new Promise(function (resolve) { - lambda._updateScheduleEvents(schedule, 'testfunc', eventSourceList.ScheduleEvents, function(err, results) { + lambda._updateScheduleEvents(schedule, functionArn, eventSourceList.ScheduleEvents, function(err, results) { resolve({ err: err, results: results }); }); }).then(function (actual) { @@ -651,7 +651,7 @@ describe('node-lambda', function () { err: undefined, results: [Object.assign( eventSourcesJsonValue.ScheduleEvents[0], - { FunctionName: 'testfunc' } + { FunctionArn: functionArn } )] }; assert.deepEqual(actual, expected); From 5822fa16dc2d5307c73296024462ecae3954553b Mon Sep 17 00:00:00 2001 From: abetomo Date: Thu, 13 Apr 2017 12:12:20 +0900 Subject: [PATCH 12/12] Remove unnecessary comma --- lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index 51d6a987..61fc25e5 100644 --- a/lib/main.js +++ b/lib/main.js @@ -682,7 +682,7 @@ Lambda.prototype.deploy = function (program) { _this._updateEventSources(lambda, params.FunctionName, existingEventSourceList, eventSourceList.EventSourceMappings, function(err, results) { _callback(err, results); }); - }, + } ], function(err, results) { cb(err, results); });