mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
Merge pull request #1682 from svdgraaf/feature/remove-unneeded-outputs
Removed unneeded outputs and the corresponding tests. Added postCreat…
This commit is contained in:
commit
b32eb23c6c
@ -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)}
|
||||
},
|
||||
|
||||
@ -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',
|
||||
],
|
||||
],
|
||||
};
|
||||
|
||||
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));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -54,15 +54,6 @@
|
||||
}
|
||||
},
|
||||
"Outputs": {
|
||||
"IamRoleArnLambda": {
|
||||
"Description": "ARN of the lambda IAM role",
|
||||
"Value": {
|
||||
"Fn::GetAtt": [
|
||||
"IamRoleLambda",
|
||||
"Arn"
|
||||
]
|
||||
}
|
||||
},
|
||||
"ServerlessDeploymentBucketName": {
|
||||
"Value": {
|
||||
"Ref": "ServerlessDeploymentBucket"
|
||||
|
||||
@ -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,35 +71,9 @@ module.exports = {
|
||||
});
|
||||
},
|
||||
|
||||
addOutputVars(cfData) {
|
||||
postCreate() {
|
||||
this.serverless.cli.log('Stack successfully created.');
|
||||
|
||||
let serverlessEnvYmlPath = path
|
||||
.join(this.serverless.config.servicePath, 'serverless.env.yml');
|
||||
|
||||
// change to serverless.env.yaml if the file could not be found
|
||||
if (!this.serverless.utils.fileExistsSync(serverlessEnvYmlPath)) {
|
||||
serverlessEnvYmlPath = path
|
||||
.join(this.serverless.config.servicePath, 'serverless.env.yaml');
|
||||
}
|
||||
|
||||
return this.serverless.yamlParser.parse(serverlessEnvYmlPath).then(parsedServerlessEnvYml => {
|
||||
const serverlessEnvYml = parsedServerlessEnvYml;
|
||||
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
|
||||
serverlessEnvYml.stages[this.options.stage]
|
||||
.regions[this.options.region].vars = regionVars;
|
||||
});
|
||||
this.serverless.utils.writeFileSync(serverlessEnvYmlPath, serverlessEnvYml);
|
||||
return BbPromise.resolve();
|
||||
});
|
||||
return BbPromise.resolve();
|
||||
},
|
||||
|
||||
createStack() {
|
||||
@ -118,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);
|
||||
|
||||
@ -131,45 +131,6 @@ describe('createStack', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#addOutputVars()', () => {
|
||||
it('should addOutputVariables to memory and serverless.env.yml', () => {
|
||||
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(serverlessEnvYmlPath))
|
||||
.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();
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user