Merge branch 'cf-deploy' of github.com:jaws-framework/JAWS into cf-deploy

This commit is contained in:
doapp-ryanp 2015-09-16 12:29:47 -05:00
commit f4f9ead06f
12 changed files with 71 additions and 58 deletions

View File

@ -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

19
docs/aws-modules.md Normal file
View File

@ -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 dont need versioning and dependency management, so you can simply install them from their github url using jaws install `<github url>`.
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.

View File

@ -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://<proj jaws.json:envVarBucket.name>/JAWS/envVars/<projectName>/<stage>`
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://<proj jaws.json:envVarBucket.name>/JAWS/envVars/<projectName>/<stage>`
Supported operations:

View File

@ -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`

View File

@ -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

View File

@ -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 dont need versioning and dependency management, so you can simply install them from their github url using jaws install `<github url>`.
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.

19
docs/resources-cf-json.md Normal file
View File

@ -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`

View File

@ -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

View File

@ -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,

View File

@ -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) {

View File

@ -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');
});

View File

@ -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();
})