From 6d1b3598c3eb5378f6b343b72be3f600a400a522 Mon Sep 17 00:00:00 2001 From: Austen Collins Date: Mon, 7 Sep 2015 09:36:47 -0700 Subject: [PATCH] fix variable names, change test ENV variable names --- lib/commands/deploy_api.js | 4 +- lib/commands/new.js | 17 ++-- lib/templates/jaws-cf.json | 6 +- tests/cli/deploy_api.js | 8 +- tests/cli/deploy_lambda.js | 6 +- tests/cli/env.js | 2 +- tests/cli/generate.js | 2 +- tests/cli/install.js | 2 +- tests/cli/tag.js | 2 +- tests/config.js | 4 +- tests/test-prj/jaws-cf.json | 160 ++++++++++++++++++++++++++++++------ tests/test_utils.js | 2 +- 12 files changed, 163 insertions(+), 52 deletions(-) diff --git a/lib/commands/deploy_api.js b/lib/commands/deploy_api.js index 9c662dfde..9d0d9ca69 100644 --- a/lib/commands/deploy_api.js +++ b/lib/commands/deploy_api.js @@ -37,7 +37,7 @@ function ApiDeployer(stage, region, prjRootPath, prjJson, prjCreds) { _this._prjCreds = prjCreds; _this._endpoints = []; _this._resources = []; - _this._awsAccountNumber = _this._region.iamRoleArnApiG.replace('arn:aws:iam::', '').split(':')[0]; + _this._awsAccountNumber = _this._region.iamRoleArnApiGateway.replace('arn:aws:iam::', '').split(':')[0]; _this._restApiId = _this._region.restApiId ? _this._region.restApiId : null; // Instantiate API Gateway Client @@ -405,7 +405,7 @@ ApiDeployer.prototype._createEndpointIntegration = Promise.method(function(endpo endpoint.lambda.functionName, ].join('_-_').replace(/ /g, '') + '/invocations', - credentials: _this._region.iamRoleArnApiG, + credentials: _this._region.iamRoleArnApiGateway, requestParameters: endpoint.endpoint.requestParameters || {}, requestTemplates: endpoint.endpoint.requestTemplates || {}, cacheNamespace: endpoint.endpoint.cacheNamespace || null, diff --git a/lib/commands/new.js b/lib/commands/new.js index 27c0a8e7c..8005935d9 100644 --- a/lib/commands/new.js +++ b/lib/commands/new.js @@ -355,7 +355,6 @@ function _createCfStack() { function() { // Stop Spinner, inform spinner.stop(true); - console.log(stackData.Stacks[0].Outputs); console.log('CloudFormation Stack ' + stackData.Stacks[0].StackName + ' successfully created.'); return resolve(stackData.Stacks[0].Outputs); } @@ -373,15 +372,15 @@ function _createCfStack() { */ function _createProjectJson(cfOutputs) { - var iamRoleLambdaArn, - iamRoleApiGatewayArn = null; + var iamRoleArnLambda, + iamRoleArnApiGateway = null; for (var i = 0; i < cfOutputs.length; i++) { - if (cfOutputs[i].OutputKey === 'IamRoleLambdaArn') { - iamRoleLambdaArn = cfOutputs[i].OutputValue; + if (cfOutputs[i].OutputKey === 'IamRoleArnLambda') { + iamRoleArnLambda = cfOutputs[i].OutputValue; } - if (cfOutputs[i].OutputKey === 'IamRoleApiGatewayArn') { - iamRoleApiGatewayArn = cfOutputs[i].OutputValue; + if (cfOutputs[i].OutputKey === 'IamRoleArnApiGateway') { + iamRoleArnApiGateway = cfOutputs[i].OutputValue; } } @@ -399,8 +398,8 @@ function _createProjectJson(cfOutputs) { jawsJson.project.stages[project.stage] = []; jawsJson.project.stages[project.stage].push({ region: project.region, - iamRoleArnLambda: iamRoleLambdaArn, - iamRoleApiGatewayArn: iamRoleApiGatewayArn + iamRoleArnLambda: iamRoleArnLambda, + iamRoleArnApiGateway: iamRoleArnApiGateway }); jawsJson.project.envVarBucket = { diff --git a/lib/templates/jaws-cf.json b/lib/templates/jaws-cf.json index 7392cf992..8f3c2d134 100644 --- a/lib/templates/jaws-cf.json +++ b/lib/templates/jaws-cf.json @@ -134,7 +134,7 @@ "Fn::Join": [ ":", [ - "arn:aws:lambda", + "arn:aws:logs", { "Ref" : "AWS::Region" }, "*:*" ] @@ -207,7 +207,7 @@ } }, "Outputs": { - "IamRoleLambdaArn": { + "IamRoleArnLambda": { "Description": "ARN of the lambda IAM role", "Value": { "Fn::GetAtt": [ @@ -216,7 +216,7 @@ ] } }, - "IamRoleApiGatewayArn": { + "IamRoleArnApiGateway": { "Description": "ARN of the api gateway IAM role", "Value": { "Fn::GetAtt": [ diff --git a/tests/cli/deploy_api.js b/tests/cli/deploy_api.js index 84dc7c04f..b00374467 100644 --- a/tests/cli/deploy_api.js +++ b/tests/cli/deploy_api.js @@ -18,13 +18,13 @@ var Jaws = require('../../lib/index.js'), describe('Test deploy api command', function() { - before(function() { + before(function(done) { projPath = testUtils.createTestProject( config.name, config.region, config.stage, config.iamRoleArnLambda, - config.iamRoleArnApiG, + config.iamRoleArnApiGateway, config.envBucket); process.chdir(path.join(projPath, 'back/lambdas/users/show')); JAWS = new Jaws(); @@ -33,6 +33,8 @@ describe('Test deploy api command', function() { lambdaPaths.lambda1 = path.join(projPath, 'back', 'lambdas', 'users', 'show', 'jaws.json'); lambdaPaths.lambda2 = path.join(projPath, 'back', 'lambdas', 'users', 'signin', 'jaws.json'); lambdaPaths.lambda3 = path.join(projPath, 'back', 'lambdas', 'users', 'signup', 'jaws.json'); + + done(); }); after(function(done) { @@ -44,7 +46,7 @@ describe('Test deploy api command', function() { this.timeout(0); - theCmd.deployApi(config.stage, config.region, true) + theCmd.deployApi(JAWS, config.stage, config.region, true) .then(function() { done(); }) diff --git a/tests/cli/deploy_lambda.js b/tests/cli/deploy_lambda.js index c30e64285..2137f0f58 100644 --- a/tests/cli/deploy_lambda.js +++ b/tests/cli/deploy_lambda.js @@ -15,18 +15,19 @@ var config = require('../config'), describe('Test "deploy lambda" command', function() { - before(function() { + before(function(done) { projPath = testUtils.createTestProject( config.name, config.region, config.stage, config.iamRoleArnLambda, - config.iamRoleArnApiG, + config.iamRoleArnApiGateway, config.envBucket, ['back']); process.chdir(projPath); JAWS = new Jaws(); + done(); }); after(function(done) { @@ -74,6 +75,5 @@ describe('Test "deploy lambda" command', function() { done(e); }); }); - }); }); \ No newline at end of file diff --git a/tests/cli/env.js b/tests/cli/env.js index d91249532..a91246be5 100644 --- a/tests/cli/env.js +++ b/tests/cli/env.js @@ -22,7 +22,7 @@ describe('Test "env" command', function() { config.region, config.stage, config.iamRoleArnLambda, - config.iamRoleArnApiG, + config.iamRoleArnApiGateway, config.envBucket); process.chdir(path.join(projPath, 'back', 'lambdas', 'users', 'show')); JAWS = new Jaws(); diff --git a/tests/cli/generate.js b/tests/cli/generate.js index afa800dbd..e1be9f166 100644 --- a/tests/cli/generate.js +++ b/tests/cli/generate.js @@ -26,7 +26,7 @@ describe('Test generate command', function() { config.region, config.stage, config.iamRoleArnLambda, - config.iamRoleArnApiG, + config.iamRoleArnApiGateway, config.envBucket); process.chdir(projPath); diff --git a/tests/cli/install.js b/tests/cli/install.js index 7a155d2d3..8ff45dff3 100644 --- a/tests/cli/install.js +++ b/tests/cli/install.js @@ -23,7 +23,7 @@ describe('Test "install" command', function() { config.region, config.stage, config.iamRoleArnLambda, - config.iamRoleArnApiG, + config.iamRoleArnApiGateway, config.envBucket); process.chdir(path.join(projPath, 'back', 'lambdas', 'users', 'show')); JAWS = new Jaws(); diff --git a/tests/cli/tag.js b/tests/cli/tag.js index bfccd287b..109b0fd2c 100644 --- a/tests/cli/tag.js +++ b/tests/cli/tag.js @@ -25,7 +25,7 @@ describe('Test "tag" command', function() { config.region, config.stage, config.iamRoleArnLambda, - config.iamRoleArnApiG, + config.iamRoleArnApiGateway, config.envBucket); process.chdir(projPath); diff --git a/tests/config.js b/tests/config.js index 6d29ff2e6..fcbac615a 100644 --- a/tests/config.js +++ b/tests/config.js @@ -15,8 +15,8 @@ var config = { region: 'us-east-1', envBucket: process.env.TEST_JAWS_ENV_BUCKET, profile: process.env.TEST_JAWS_PROFILE, - iamRoleArnApiG: process.env.TEST_JAWS_IAM_ROLE, - iamRoleArnLambda: process.env.TEST_JAWS_LAMBDA_DEPLOY_IAM_ROLE, + iamRoleArnApiGateway: process.env.TEST_JAWS_APIGATEWAY_ROLE, + iamRoleArnLambda: process.env.TEST_JAWS_LAMBDA_ROLE, }; AWS.config.credentials = new AWS.SharedIniFileCredentials({ diff --git a/tests/test-prj/jaws-cf.json b/tests/test-prj/jaws-cf.json index 1a7a33175..7392cf992 100644 --- a/tests/test-prj/jaws-cf.json +++ b/tests/test-prj/jaws-cf.json @@ -3,30 +3,21 @@ "Description": "The AWS CloudFormation template for this JAWS project", "Parameters": { "aaProjectName": { - "Type": "String", - "Default": "jaws-new-EJYMNmGh", - "AllowedValues": [ - "jaws-new-EJYMNmGh" - ] + "Type": "String" }, "aaStage": { - "Type": "String", - "Default": "dev" + "Type": "String" }, "aaDataModelPrefix": { - "Type": "String", - "Default": "dev", - "AllowedValues": [ - "dev" - ] + "Type": "String" }, "aaHostedZoneName": { "Type": "String", - "Default": "myapp.com" + "Default": "myjawsproject.com" }, "aaNotficationEmail": { "Type": "String", - "Default": "austen@servant.co" + "Default": "you@you.com" }, "aaDefaultDynamoRWThroughput": { "Type": "String", @@ -34,7 +25,7 @@ } }, "Resources": { - "LambdaRole": { + "IamRoleLambda": { "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { @@ -56,24 +47,63 @@ "Path": "/" } }, - "Profile": { + "IamRoleApiGateway": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + }, + "Action": [ + "sts:AssumeRole" + ] + } + ] + }, + "Path": "/" + } + }, + "IamInstanceProfileLambda": { "Type": "AWS::IAM::InstanceProfile", "Properties": { "Path": "/", "Roles": [ { - "Ref": "LambdaRole" + "Ref": "IamRoleLambda" } ] } }, - "Group": { - "Type": "AWS::IAM::Group", + "IamInstanceProfileApiGateway": { + "Type": "AWS::IAM::InstanceProfile", "Properties": { - "Path": "/dataModel/" + "Path": "/", + "Roles": [ + { + "Ref": "IamRoleApiGateway" + } + ] } }, - "DataModelPolicy": { + "IamGroupLambda": { + "Type": "AWS::IAM::Group", + "Properties": { + "Path": "/" + } + }, + "IamGroupApiGateway": { + "Type": "AWS::IAM::Group", + "Properties": { + "Path": "/" + } + }, + "IamPolicyLambda": { "Type": "AWS::IAM::Policy", "Properties": { "PolicyName": { @@ -85,7 +115,8 @@ }, { "Ref": "aaProjectName" - } + }, + "lambda" ] ] }, @@ -99,21 +130,100 @@ "logs:CreateLogStream", "logs:PutLogEvents" ], - "Resource": "arn:aws:logs:*:*:*" + "Resource": { + "Fn::Join": [ + ":", + [ + "arn:aws:lambda", + { "Ref" : "AWS::Region" }, + "*:*" + ] + ] + } } ] }, "Roles": [ { - "Ref": "LambdaRole" + "Ref": "IamRoleLambda" } ], "Groups": [ { - "Ref": "Group" + "Ref": "IamGroupLambda" } ] } + }, + "IamPolicyApiGateway": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyName": { + "Fn::Join": [ + "_-_", + [ + { + "Ref": "aaStage" + }, + { + "Ref": "aaProjectName" + }, + "api-gateway" + ] + ] + }, + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "lambda:InvokeFunction" + ], + "Resource": { + "Fn::Join": [ + ":", + [ + "arn:aws:lambda", + { "Ref" : "AWS::Region" }, + "*:*" + ] + ] + } + } + ] + }, + "Roles": [ + { + "Ref": "IamRoleApiGateway" + } + ], + "Groups": [ + { + "Ref": "IamGroupApiGateway" + } + ] + } + } + }, + "Outputs": { + "IamRoleLambdaArn": { + "Description": "ARN of the lambda IAM role", + "Value": { + "Fn::GetAtt": [ + "IamRoleLambda", + "Arn" + ] + } + }, + "IamRoleApiGatewayArn": { + "Description": "ARN of the api gateway IAM role", + "Value": { + "Fn::GetAtt": [ + "IamRoleApiGateway", + "Arn" + ] + } } } } \ No newline at end of file diff --git a/tests/test_utils.js b/tests/test_utils.js index e75ffbf0f..4d942d621 100644 --- a/tests/test_utils.js +++ b/tests/test_utils.js @@ -61,7 +61,7 @@ module.exports.createTestProject = function(projectName, projectJSON.project.stages[projectStage] = [{ region: projectRegion, iamRoleArnLambda: projectLambdaIAMRole, - iamRoleArnApiG: projectApiGIAMRole + iamRoleArnApiGateway: projectApiGIAMRole },]; projectJSON.project.envVarBucket = { name: projectEnvBucket,