From dd785825c6063b7ad12467acf23b90cac915c44c Mon Sep 17 00:00:00 2001 From: Austen Collins Date: Wed, 16 Sep 2015 09:22:01 -0700 Subject: [PATCH 1/2] sync --- docs/admin-env.md | 4 +++- docs/aws-modules.md | 19 +++++++++++++++++++ docs/commands.md | 9 +++++---- docs/jaws-cf-json.md | 18 ------------------ docs/jaws-json.md | 11 +++++------ docs/plugin-module-guide.md | 7 ------- docs/resources-cf-json.md | 19 +++++++++++++++++++ 7 files changed, 51 insertions(+), 36 deletions(-) create mode 100644 docs/aws-modules.md delete mode 100644 docs/jaws-cf-json.md delete mode 100644 docs/plugin-module-guide.md create mode 100644 docs/resources-cf-json.md diff --git a/docs/admin-env.md b/docs/admin-env.md index ec8f2e0d7..fd2621d2b 100644 --- a/docs/admin-env.md +++ b/docs/admin-env.md @@ -1,4 +1,6 @@ -This file tells the JAWS tooling what profile from the [shared credentials](http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html#Credentials_from_the_Shared_Credentials_File_____aws_credentials_) file (`~/.aws/credentials`) is loaded when doing administrative tasks that interact with AWS. +This file tells the JAWS tooling what profile from the +[shared credentials](http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html#Credentials_from_the_Shared_Credentials_File_____aws_credentials_) +file (`~/.aws/credentials`) is loaded when doing administrative tasks that interact with AWS. Here is an example diff --git a/docs/aws-modules.md b/docs/aws-modules.md new file mode 100644 index 000000000..d1a6cd970 --- /dev/null +++ b/docs/aws-modules.md @@ -0,0 +1,19 @@ +# JAWS: AWS-Modules + +**Amazon Web Services Modules (aws-modules)** are the building blocks of your JAWS serverless back-end. + +Each aws-module contains one or multiple AWS Lambda functions, plus their AWS resource dependencies defined via AWS +CloudFormation. You can read more about them in [their Github repo](https://github.com/awsm-org/awsm). + +Every time you create a lambda function or endpoint within your JAWS project, +you create an aws-module. + + + + +JAWS is extremely modular by design. JAWS-modules must include code and a [jaws.json](./jaws-json.md) file. +jaws-modules differ from npm-modules in that they are mostly “templates”. Since they are merely templates, we don’t need versioning and dependency management, so you can simply install them from their github url using jaws install ``. + +The convention is to have a directory per lambda, under a resource dir in your `back` folder. + +Check out the [JAWS test project](../tests/test-prj) that shows off the modular philosophy of JAWS. diff --git a/docs/commands.md b/docs/commands.md index 4a4afcfae..1e2dec012 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -2,7 +2,7 @@ ### jaws new -Creates a new project, new region in existing project, or new stage in existing region. The new command by default creates resources in AWS (via CloudFormation) +Creates a new project, new stage in existing project, or a new region in an existing stage. The new command by default creates resources in AWS (via CloudFormation) ##### type `project` @@ -26,8 +26,9 @@ Creates a new stage in existing region. By default executes CloudFormation to m Creates one or both of the following in the `back/aws_modules` folder: -* A lambda function with basic skeleton -* An API gateway configuration + +* A lambda function in the `back/aws_modules` folder with basic scaffolding. +* An API gateway configuration ### jaws dash @@ -35,7 +36,7 @@ Interactive dashboard used to get an overview of your project and deploy resourc ### jaws env -Manages enviornment variable files for all stages. There is a reserved stage `local` which stores the env var file in `back/.env`. Otherwise they are stored is s3 at `s3:///JAWS/envVars//` +Manages environment variable files for all stages. There is a reserved stage `local` which stores the env var file in `back/.env`. Otherwise they are stored is s3 at `s3:///JAWS/envVars//` Supported operations: diff --git a/docs/jaws-cf-json.md b/docs/jaws-cf-json.md deleted file mode 100644 index 8e1a15779..000000000 --- a/docs/jaws-cf-json.md +++ /dev/null @@ -1,18 +0,0 @@ -This is the JAWS [CloudFormation](https://aws.amazon.com/cloudformation/) file. - -JAWS [plug-in modules](./jaws-json.md#jaws-plug-in-module) can merge data into this file by implementing the [`cfExtensions`](docs/jaws-json.md#cfextensions-attributes) attribute in the `jaws.json`. - - -The following CloudFormation Parameters are standardized JAWS project variables that all cfExtensions statements should utilize via `Ref`. Note: `aa` is used so they show up at top of CloudFormation web UI: - -* `aaHostedZone` -* `aaStage` -* `aaProjectName` -* `aaDataModelStage` [what's this?](https://github.com/jaws-framework/JAWS/wiki/v1:best-practices#cloud-formation-segmentation) -* `aaNotficationEmail` -* `aaDefaultDynamoRWThroughput` - -The following are CloudFormation Resource names that JAWS module creators can `Ref` in their CF Templates: - -* `IamRoleLambda` -* `IamRoleApiGateway` diff --git a/docs/jaws-json.md b/docs/jaws-json.md index 1f7e0f428..4183bc96a 100644 --- a/docs/jaws-json.md +++ b/docs/jaws-json.md @@ -1,9 +1,8 @@ # jaws.json -The `jaws.json` file contains configuration details for the included code and authorship details for easy publishing. This is similar to `package.json` but for jaws-modules. `jaws.json` files exist at a few different levels in a JAWS proejct: -* **Project**: lives at the root of your project. Defines things like stages. [example here](../examples/project-jaws.json) -* **`aws_modules` directory**: `jaws.json` exists for every lambda function. It defines things like memory size and api gateway endpoint configuration. [example here](../examples/lambda-jaws.json) -* **JAWS plug-in module**: lives at the root of the hosted project +The `jaws.json` file contains project configuration and authorship details. +It defines things like the project's stages and regions within each stage, + [like in this example.](../examples/project-jaws.json) ## Common jaws.json attributes @@ -31,10 +30,10 @@ See lambda `jaws.json` [example here](../examples/lambda-jaws.json) **Note**: All of the attrs below assume the `lambda` attribute key prefix. * `Handler,MemorySize,Runtime,Timeout`: can all be found in the [aws docs](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html) - * We recommend 1024 memory to improve cold/warm start times. `handler` is relative to back dir + * We recommend 1024 memory to improve cold/warm start times. `handler` is relative to back dir * `envVars`: An array of environment variable names this project/module or lambda requires * `deploy`: if true, this app will be deployed the next time the `jaws deploy --tags` is run. See `deploy` command docs for more info. -* `package`: How the code is packaged up into a zip file +* `package`: How the code is packaged up into a zip file * `optimize`: How code is optimized for node runtimes, to improve lambda cold start time * `builder`: only `"browserify"` or `false` supported now. If `false` will just zip up entire `back` dir * `minify`: js minify or not diff --git a/docs/plugin-module-guide.md b/docs/plugin-module-guide.md deleted file mode 100644 index 028cf25db..000000000 --- a/docs/plugin-module-guide.md +++ /dev/null @@ -1,7 +0,0 @@ -# JAWS plug-in module guide - -JAWS is exteremly modular by design. JAWS-modules must include code and a [jaws.json](./jaws-json.md) file. jaws-modules differ from npm-modules in that they are mostly “templates”. Since they are merely templates, we don’t need versioning and dependency management, so you can simply install them from their github url using jaws install ``. - -The convention is to have a directory per lambda, under a resource dir in your `back` folder. - -Check out the [JAWS test project](../tests/test-prj) that shows off the modular philosophy of JAWS. diff --git a/docs/resources-cf-json.md b/docs/resources-cf-json.md new file mode 100644 index 000000000..c3eb0ff7f --- /dev/null +++ b/docs/resources-cf-json.md @@ -0,0 +1,19 @@ +This is the JAWS [CloudFormation](https://aws.amazon.com/cloudformation/) file. + +AWS-Modules [aws-modules](./jaws-json.md#jaws-plug-in-module) can merge data into this file by implementing the +[`resources`](docs/jaws-json.md#cfextensions-attributes) attribute in the `awsm.json`. + +The following CloudFormation Parameters are standardized JAWS project variables that all aws-module CloudFormation +templates should utilize via `Ref`. Note: `aa` is used so they show up at top of CloudFormation web UI: + +* `aaHostedZone` +* `aaStage` +* `aaProjectName` +* `aaDataModelStage` [what's this?](https://github.com/jaws-framework/JAWS/wiki/v1:best-practices#cloud-formation-segmentation) +* `aaNotficationEmail` +* `aaDefaultDynamoRWThroughput` + +The following are CloudFormation Resource names that aws-module creators can `Ref` in their CF Templates: + +* `IamRoleLambda` +* `IamRoleApiGateway` From 9d40c880f4f26351962725c4efb9296744ca8d07 Mon Sep 17 00:00:00 2001 From: Austen Collins Date: Wed, 16 Sep 2015 10:22:49 -0700 Subject: [PATCH 2/2] dash: refactor dash command for awsm and cf deployment --- lib/commands/dash.js | 23 ++++++++++++----------- lib/commands/deploy_endpoint.js | 2 +- lib/utils/index.js | 7 ++++--- tests/all.js | 2 +- tests/cli/dash.js | 8 ++------ 5 files changed, 20 insertions(+), 22 deletions(-) diff --git a/lib/commands/dash.js b/lib/commands/dash.js index 1975424c6..e548da845 100644 --- a/lib/commands/dash.js +++ b/lib/commands/dash.js @@ -23,24 +23,25 @@ var JawsError = require('../jaws-error'), * @returns {Promise} */ -module.exports.run = function(JAWS, stage, regions, allTagged) { - var command = new CMD(JAWS, stage, regions, allTagged); +module.exports.run = function(JAWS, stage, region, allTagged) { + var command = new CMD(JAWS, stage, region, allTagged); return command.run(); }; /** - * + * CMD Class * @param JAWS * @param stage * @param regions * @param allTagged * @constructor */ -function CMD(JAWS, stage, regions, allTagged) { + +function CMD(JAWS, stage, region, allTagged) { this._JAWS = JAWS; this._allTagged = allTagged || false; this._stage = stage || null; - this._regions = regions || []; + this._regions = region ? [region] : []; this._choices = []; } @@ -53,7 +54,7 @@ CMD.prototype.run = Promise.method(function() { var _this = this; _this._report = { targetLambdas: 0, - targetEndpoints: 0 + targetEndpoints: 0, }; return _this._JAWS.validateProject() @@ -63,8 +64,7 @@ CMD.prototype.run = Promise.method(function() { // If !allTagged, Show Dashboard if (!_this._allTagged) { - return Promise.try(function() { - }) + return Promise.try(function() {}) .bind(_this) .then(_this._prepareResources) .then(_this._prepareSummary) @@ -158,7 +158,7 @@ CMD.prototype._prepareResources = Promise.method(function() { key: ' L) ', value: jsonPaths[i], type: 'lambda', - label: json.lambda.functionName, + label: utils.generateLambdaName(json), }; // Create path @@ -168,12 +168,13 @@ CMD.prototype._prepareResources = Promise.method(function() { } // Add Endpoint - if (json.endpoint) { + if (json.apiGateway) { module.endpoint = { key: ' E) ', value: jsonPaths[i], type: 'endpoint', - label: '/' + json.endpoint.path + ' - ' + json.endpoint.method, + label: '/' + json.apiGateway.cloudFormation.Path + + ' - ' + json.apiGateway.cloudFormation.Method, }; // Create path diff --git a/lib/commands/deploy_endpoint.js b/lib/commands/deploy_endpoint.js index d97a88a56..0a0641617 100644 --- a/lib/commands/deploy_endpoint.js +++ b/lib/commands/deploy_endpoint.js @@ -516,7 +516,7 @@ ApiDeployer.prototype._createEndpointIntegration = Promise.method(function(endpo + ':function:' + [_this._stage, _this._prjJson.name, - utils.generateLambdaName(endpoint.lambda), + utils.generateLambdaName(endpoint), ].join('_-_').replace(/ /g, '') + '/invocations', credentials: _this._regionJson.iamRoleArnApiGateway, diff --git a/lib/utils/index.js b/lib/utils/index.js index a41ff0df5..cc006d809 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -165,6 +165,7 @@ module.exports.findAllEndpoints = function(projectRootPath) { * @param startPath * @returns {Promise} list of full paths to awsm.json files */ + module.exports.findAllAwsmJsons = function(startPath) { return this.readRecursively(startPath, '*awsm.json') .then(function(jsonPaths) { @@ -203,12 +204,12 @@ module.exports.writeFile = function(filePath, contents) { /** * Generate Lambda Name - * @param lambdaAwsmJson + * @param awsmJson * @returns {string} */ -module.exports.generateLambdaName = function(lambdaAwsmJson) { - var handlerName = lambdaAwsmJson.lambda.cloudFormation.Handler.replace('aws_modules', ''), +module.exports.generateLambdaName = function(awsmJson) { + var handlerName = awsmJson.lambda.cloudFormation.Handler.replace('aws_modules', ''), resourceAction = handlerName.substr(0, handlerName.lastIndexOf('/')); return 'l' + resourceAction.replace(/\/([a-z])/g, function(g) { diff --git a/tests/all.js b/tests/all.js index 105190cfa..da81cc4a8 100644 --- a/tests/all.js +++ b/tests/all.js @@ -25,7 +25,7 @@ describe('AllTests', function() { // //require('./cli/dash'); //require('./cli/deploy_lambda'); - require('./cli/deploy_endpoint'); + //require('./cli/deploy_endpoint'); //require('./cli/new_stage_region'); //require('./cli/new_project'); }); \ No newline at end of file diff --git a/tests/cli/dash.js b/tests/cli/dash.js index a0e78109c..52c9898a2 100644 --- a/tests/cli/dash.js +++ b/tests/cli/dash.js @@ -46,19 +46,15 @@ describe('Test "dash" command', function() { return CMDtag.tagAll(JAWS, 'endpoint'); }) .then(function() { - return done(); + done(); }); }); - after(function(done) { - done(); - }); - describe('Positive tests', function() { it('Dash deployment via tagged resources', function(done) { this.timeout(0); - CMDdash.run(JAWS, config.stage, [config.region], true) + CMDdash.run(JAWS, config.stage, config.region, true) .then(function() { done(); })