diff --git a/lib/plugins/aws/deploy/compile/events/apiGateway/lib/methods.js b/lib/plugins/aws/deploy/compile/events/apiGateway/lib/methods.js index 5c70d5827..a2a16093d 100644 --- a/lib/plugins/aws/deploy/compile/events/apiGateway/lib/methods.js +++ b/lib/plugins/aws/deploy/compile/events/apiGateway/lib/methods.js @@ -33,15 +33,6 @@ module.exports = { method.substr(1).toLowerCase(); const extractedResourceId = resourceLogicalId.match(/\d+$/)[0]; - const serviceName = this.serverless.service.service; - const awsAccountNumber = this.serverless.service - .getVariables(this.options.stage, this.options.region).iamRoleArnLambda - .match(/(.*):(.*):(.*):(.*):(.*):role\/.*/)[5]; - - const lambdaUri = `arn:aws:apigateway:${ - this.options.region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${ - this.options.region}:${awsAccountNumber}:function:${ - serviceName}-${this.options.stage}-${functionName}/invocations`; // universal velocity template // provides `{body, method, headers, query, path, identity, stageVariables} = event` @@ -94,7 +85,17 @@ module.exports = { "Integration" : { "IntegrationHttpMethod" : "POST", "Type" : "AWS", - "Uri" : "${lambdaUri}", + "Uri" : { + "Fn::Join": [ "", + [ + "arn:aws:apigateway:", + {"Ref" : "AWS::Region"}, + ":lambda:path/2015-03-31/functions/", + {"Fn::GetAtt" : ["${functionName}", "Arn"]}, + "/invocations" + ] + ] + }, "RequestTemplates" : { "application/json" : ${JSON.stringify(DEFAULT_JSON_REQUEST_TEMPLATE)} }, diff --git a/lib/plugins/aws/deploy/compile/events/apiGateway/tests/methods.js b/lib/plugins/aws/deploy/compile/events/apiGateway/tests/methods.js index eb14853c7..48f2a74df 100644 --- a/lib/plugins/aws/deploy/compile/events/apiGateway/tests/methods.js +++ b/lib/plugins/aws/deploy/compile/events/apiGateway/tests/methods.js @@ -162,21 +162,25 @@ describe('#compileMethods()', () => { }); it('should set the correct lambdaUri', () => { - const lambdaUri = `arn:aws:apigateway:${ - awsCompileApigEvents.options.region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${ - awsCompileApigEvents.options.region}:12345678:function:${ - awsCompileApigEvents.serverless.service.service}-${ - awsCompileApigEvents.options.stage}-first/invocations`; + const lambdaUriObject = { + 'Fn::Join': ['', [ + 'arn:aws:apigateway:', + { Ref: 'AWS::Region' }, + ':lambda:path/2015-03-31/functions/', + { 'Fn::GetAtt': ['first', 'Arn'] }, + '/invocations' // eslint-disable-line comma-dangle + ]] // eslint-disable-line comma-dangle + }; return awsCompileApigEvents.compileMethods().then(() => { expect( - awsCompileApigEvents.serverless.service.resources.Resources.PostMethodApigEvent0.Properties - .Integration.Uri - ).to.equal(lambdaUri); + JSON.stringify(awsCompileApigEvents.serverless.service.resources + .Resources.PostMethodApigEvent0.Properties.Integration.Uri + )).to.equal(JSON.stringify(lambdaUriObject)); expect( - awsCompileApigEvents.serverless.service.resources.Resources.GetMethodApigEvent1.Properties - .Integration.Uri - ).to.equal(lambdaUri); + JSON.stringify(awsCompileApigEvents.serverless.service.resources + .Resources.GetMethodApigEvent1.Properties.Integration.Uri + )).to.equal(JSON.stringify(lambdaUriObject)); }); }); }); diff --git a/lib/plugins/aws/deploy/lib/core-cf.json b/lib/plugins/aws/deploy/lib/core-cf.json index b3d5a10fe..04440c4d5 100644 --- a/lib/plugins/aws/deploy/lib/core-cf.json +++ b/lib/plugins/aws/deploy/lib/core-cf.json @@ -54,15 +54,6 @@ } }, "Outputs": { - "IamRoleArnLambda": { - "Description": "ARN of the lambda IAM role", - "Value": { - "Fn::GetAtt": [ - "IamRoleLambda", - "Arn" - ] - } - }, "ServerlessDeploymentBucketName": { "Value": { "Ref": "ServerlessDeploymentBucket" diff --git a/lib/plugins/aws/deploy/lib/createStack.js b/lib/plugins/aws/deploy/lib/createStack.js index a5448bb20..adb446d77 100644 --- a/lib/plugins/aws/deploy/lib/createStack.js +++ b/lib/plugins/aws/deploy/lib/createStack.js @@ -1,8 +1,6 @@ 'use strict'; const BbPromise = require('bluebird'); -const path = require('path'); -const lowerFirst = require('lodash').lowerFirst; const async = require('async'); module.exports = { @@ -73,28 +71,9 @@ module.exports = { }); }, - addOutputVars(cfData) { + postCreate() { this.serverless.cli.log('Stack successfully created.'); - - const serverlessEnvYamlPath = path - .join(this.serverless.config.servicePath, 'serverless.env.yaml'); - return this.serverless.yamlParser.parse(serverlessEnvYamlPath).then(parsedServerlessEnvYaml => { - const serverlessEnvYaml = parsedServerlessEnvYaml; - cfData.Outputs.forEach((output) => { - const varName = lowerFirst(output.OutputKey); - - // add vars to memory - const regionVars = this.serverless.service - .getVariables(this.options.stage, this.options.region); - regionVars[varName] = output.OutputValue; - - // add vars to file system - serverlessEnvYaml.stages[this.options.stage] - .regions[this.options.region].vars = regionVars; - }); - this.serverless.utils.writeFileSync(serverlessEnvYamlPath, serverlessEnvYaml); - return BbPromise.resolve(); - }); + return BbPromise.resolve(); }, createStack() { @@ -111,7 +90,7 @@ module.exports = { return BbPromise.bind(this) .then(this.create) .then(this.monitorCreate) - .then(this.addOutputVars); + .then(this.postCreate); } throw new this.serverless.classes.Error(e); diff --git a/lib/plugins/aws/deploy/tests/createStack.js b/lib/plugins/aws/deploy/tests/createStack.js index 0cec52b8e..05bb5f238 100644 --- a/lib/plugins/aws/deploy/tests/createStack.js +++ b/lib/plugins/aws/deploy/tests/createStack.js @@ -131,45 +131,6 @@ describe('createStack', () => { }); }); - describe('#addOutputVars()', () => { - it('should addOutputVariables to memory and serverless.env.yaml', () => { - const cfDataMock = { - Outputs: [ - { - OutputKey: 'IamRoleArnLambda', - OutputValue: 'someValue', - }, - ], - }; - - awsDeploy.serverless.service.environment = { - vars: {}, - stages: { - dev: { - vars: {}, - regions: { - 'us-east-1': { - vars: {}, - }, - }, - }, - }, - }; - - return awsDeploy.addOutputVars(cfDataMock) - .then(() => awsDeploy.serverless.yamlParser.parse(serverlessEnvYamlPath)) - .then((yaml) => { - // assert var added to memory - expect(awsDeploy.serverless.service.environment.stages.dev - .regions['us-east-1'].vars.iamRoleArnLambda).to.be.equal('someValue'); - - // assert var added to file - expect(yaml.stages.dev - .regions['us-east-1'].vars.iamRoleArnLambda).to.be.equal('someValue'); - }); - }); - }); - describe('#createStack()', () => { it('should resolve if stack already created', () => { const createStub = sinon @@ -205,17 +166,17 @@ describe('createStack', () => { .stub(awsDeploy, 'create').returns(BbPromise.resolve()); const monitorStub = sinon .stub(awsDeploy, 'monitorCreate').returns(BbPromise.resolve()); - const addOutputVarsStub = sinon - .stub(awsDeploy, 'addOutputVars').returns(BbPromise.resolve()); + const postCreateStub = sinon + .stub(awsDeploy, 'postCreate').returns(BbPromise.resolve()); return awsDeploy.createStack().then(() => { expect(createStub.calledOnce).to.be.equal(true); expect(monitorStub.calledAfter(createStub)).to.be.equal(true); - expect(addOutputVarsStub.calledAfter(monitorStub)).to.be.equal(true); + expect(postCreateStub.calledAfter(monitorStub)).to.be.equal(true); awsDeploy.create.restore(); awsDeploy.monitorCreate.restore(); - awsDeploy.addOutputVars.restore(); + awsDeploy.postCreate.restore(); awsDeploy.sdk.request.restore(); }); });