diff --git a/lib/Jaws.js b/lib/Jaws.js index dd3ec4470..ae93990e5 100644 --- a/lib/Jaws.js +++ b/lib/Jaws.js @@ -255,7 +255,7 @@ class Jaws { } /** - * + * Load Plugins * @param relDir string path to start from when rel paths are specified * @param pluginMetadata [{path:'path (re or loadable npm mod',config{}}] * @private diff --git a/lib/defaults/actions/FunctionDeploy.js b/lib/defaults/actions/FunctionDeploy.js index 72ab03f7f..1b8d6c793 100644 --- a/lib/defaults/actions/FunctionDeploy.js +++ b/lib/defaults/actions/FunctionDeploy.js @@ -64,6 +64,8 @@ class FunctionDeploy extends JawsPlugin { ], }); + // TODO: Add "all" option + return BbPromise.resolve(); } @@ -100,8 +102,6 @@ class FunctionDeploy extends JawsPlugin { * - If CLI, maps CLI input to event object */ - // TODO: Loop through each function, check runtime and separate accordingly - _validateAndPrepare() { let _this = this; @@ -208,15 +208,13 @@ class FunctionDeploy extends JawsPlugin { * Deploy Regions */ - // TODO: multi-language support? - _deployRegions() { let _this = this; - return BbPromise.try(function() { return _this.evt.queued.regions; }) + .bind(_this) .each(function(region) { // Deploy Type @@ -224,92 +222,114 @@ class FunctionDeploy extends JawsPlugin { // Deploy Endpoint only case "endpoint": - - // TODO: Move to re-usable function ("all" needs this too) - // TODO: No concurrency, instead process w/ error handling for API Gateway throttling - return _this.Jaws.actions.endpointPackageApiGateway(evtClone) - .bind(_this) - .then(_this.Jaws.actions.endpointProvisionApiGateway); - - // Deploy Code only (lambda) + return _this._deployEndpointByRegion(region); + break; + // Deploy Code only case "code": - - // TODO: Move to re-usable function ("all" needs this too) - - // Package Lambdas - return new BbPromise(function(resolve, reject) { - - // Create uploaded array for this region - _this.evt.uploaded[region] = []; - - // Package & Upload functions' code concurrently - // Package must be redone for each region because ENV vars are set for each region - async.eachLimit(_this.evt.queued.functions, 5, function(func, cb) { - - // Create new evt object for concurrent operations - let newEvent = { - stage: _this.evt.queued.stage, - region: JawsUtils.getProjRegionConfigForStage( - _this.Jaws._projectJson, - _this.evt.queued.stage, - region), - function: func, - }; - - // Process sub-Actions - return _this.Jaws.actions.codePackageLambdaNodejs(newEvent) - .bind(_this) - .then(_this.Jaws.actions.codeCompressLambdaNodejs) - .then(_this.Jaws.actions.codeUploadLambdaNodejs) - .then(function(evt) { - // Add Function and Region - _this.evt.uploaded[region].push(evt.function); - return cb(); - }); - - }, resolve); - }); - + return _this._processCodeByRegion(region); break; - // Deploy Code then Endpoint case "all": break; - // Default default: return BbPromise.resolve(); } }) - .then(function() { + .then(_this._provisionCodeAllRegions); + } - return new BbPromise(function(resolve, reject) { + /** + * Deploy Code By Region + * @region + */ - // If type is "endpoint", skip - if (_this.evt.queued.type === 'endpoint') return _this.evt; + _processCodeByRegion(region) { - // If type is "code" or "all", do concurrent, multi-region, CF update - async.eachLimit(Object.keys(_this.evt.uploaded), 5, function(region, cb) { + let _this = this; - let newEvent = { - stage: _this.evt.queued.stage, - region: JawsUtils.getProjRegionConfigForStage( - _this.Jaws._projectJson, - _this.evt.queued.stage, - region), - functions: _this.evt.uploaded[region], - }; + return new BbPromise(function(resolve, reject) { - return _this.Jaws.actions.codeProvisionLambdaNodejs(newEvent) - .then(function() { - return cb(); - }); + // Create uploaded array for this region + _this.evt.uploaded[region] = []; - }, function() { - return resolve(_this.evt); + // Package & Upload functions' code concurrently + // Package must be redone for each region because ENV vars are set for each region + async.eachLimit(_this.evt.queued.functions, 5, function(func, cb) { + + // Create new evt object for concurrent operations + let newEvent = { + stage: _this.evt.queued.stage, + region: JawsUtils.getProjRegionConfigForStage( + _this.Jaws._projectJson, + _this.evt.queued.stage, + region), + function: func, + }; + + // TODO: Read runtime of func + // TODO: Deploy by runtime + + // Process sub-Actions + return _this.Jaws.actions.codePackageLambdaNodejs(newEvent) + .bind(_this) + .then(_this.Jaws.actions.codeCompressLambdaNodejs) + .then(_this.Jaws.actions.codeUploadLambdaNodejs) + .then(function(evt) { + // Add Function and Region + _this.evt.uploaded[region].push(evt.function); + return cb(); }); - }); - }); + + }, resolve); + }); + } + + /** + * Provision Code All Regions + * - Initiates CloudFormation Stack Create/Update in all Regions Concurrently + */ + + _provisionCodeAllRegions() { + + let _this = this; + + return new BbPromise(function(resolve, reject) { + + // If type is "endpoint", skip + if (_this.evt.queued.type === 'endpoint') return resolve(); + + // If type is "code" or "all", do concurrent, multi-region, CF update + async.eachLimit(Object.keys(_this.evt.uploaded), 5, function(region, cb) { + + let newEvent = { + stage: _this.evt.queued.stage, + region: JawsUtils.getProjRegionConfigForStage( + _this.Jaws._projectJson, + _this.evt.queued.stage, + region), + functions: _this.evt.uploaded[region], + }; + + return _this.Jaws.actions.codeProvisionLambdaNodejs(newEvent) + .then(cb); + + }, function() { + return resolve(); + }); + }); + } + + /** + * Deploy Endpoint By Region + */ + // TODO: MAKE EVT CLONE + // TODO: Handle API Gateway Throttling Errors + _deployEndpointByRegion() { + let _this = this; + return _this.Jaws.actions.endpointPackageApiGateway(evtClone) + .bind(_this) + .then(_this.Jaws.actions.endpointProvisionApiGateway); } } diff --git a/tests/test-prj/aws_modules/bundle/browserify/lambda.awsm.json b/tests/test-prj/aws_modules/bundle/browserify/lambda.awsm.json index aed42d6b3..83a6f35a7 100644 --- a/tests/test-prj/aws_modules/bundle/browserify/lambda.awsm.json +++ b/tests/test-prj/aws_modules/bundle/browserify/lambda.awsm.json @@ -1,5 +1,5 @@ { - "name": "lBundleBrowserify", + "name": "BundleBrowserify", "envVars": [], "package": { "optimize": { diff --git a/tests/test-prj/aws_modules/bundle/nonoptimized/lambda.awsm.json b/tests/test-prj/aws_modules/bundle/nonoptimized/lambda.awsm.json index f3a04f994..c7899c8c5 100644 --- a/tests/test-prj/aws_modules/bundle/nonoptimized/lambda.awsm.json +++ b/tests/test-prj/aws_modules/bundle/nonoptimized/lambda.awsm.json @@ -1,5 +1,5 @@ { - "name": "lBundleNonoptimized", + "name": "BundleNonoptimized", "envVars": [], "package": { "optimize": { diff --git a/tests/test-prj/aws_modules/sessions/create/lambda.awsm.json b/tests/test-prj/aws_modules/sessions/create/lambda.awsm.json index 31ffb4ac0..91048d930 100644 --- a/tests/test-prj/aws_modules/sessions/create/lambda.awsm.json +++ b/tests/test-prj/aws_modules/sessions/create/lambda.awsm.json @@ -1,5 +1,5 @@ { - "name": "lSessionsCreate", + "name": "SessionsCreate", "envVars": [], "package": { "optimize": { diff --git a/tests/test-prj/aws_modules/sessions/show/lambda.awsm.json b/tests/test-prj/aws_modules/sessions/show/lambda.awsm.json index f5fa41b4e..7db402639 100644 --- a/tests/test-prj/aws_modules/sessions/show/lambda.awsm.json +++ b/tests/test-prj/aws_modules/sessions/show/lambda.awsm.json @@ -1,5 +1,5 @@ { - "name": "lSessionsShow", + "name": "SessionsShow", "envVars": [], "package": { "optimize": { diff --git a/tests/test-prj/aws_modules/users/create/lambda.awsm.json b/tests/test-prj/aws_modules/users/create/lambda.awsm.json index 6161fcd67..10c505321 100644 --- a/tests/test-prj/aws_modules/users/create/lambda.awsm.json +++ b/tests/test-prj/aws_modules/users/create/lambda.awsm.json @@ -1,5 +1,5 @@ { - "name": "lUsersCreate", + "name": "UsersCreate", "envVars": [], "package": { "optimize": {