mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
Add a validation step so that validation checks don't need to be rewritten in each compile method / step.
36 lines
1.1 KiB
JavaScript
36 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
const merge = require('lodash').merge;
|
|
const BbPromise = require('bluebird');
|
|
|
|
module.exports = {
|
|
compileDeployment() {
|
|
this.serverless.service.getAllFunctions().forEach((functionName) => {
|
|
const functionObject = this.serverless.service.getFunction(functionName);
|
|
|
|
// checking all three levels in the obj tree
|
|
// to avoid "can't read property of undefined" error
|
|
if (functionObject.events && functionObject.events.aws
|
|
&& functionObject.events.aws.http_endpoint) {
|
|
const deploymentTemplate = `
|
|
{
|
|
"Type" : "AWS::ApiGateway::Deployment",
|
|
"Properties" : {
|
|
"RestApiId" : { "Ref": "${functionName}RestApiApigEvent" },
|
|
"StageName" : "${this.options.stage}"
|
|
}
|
|
}
|
|
`;
|
|
|
|
const newDeploymentObject = {
|
|
[`${functionName}DeploymentApigEvent`]: JSON.parse(deploymentTemplate),
|
|
};
|
|
|
|
merge(this.serverless.service.resources.aws.Resources, newDeploymentObject);
|
|
}
|
|
});
|
|
|
|
return BbPromise.resolve();
|
|
},
|
|
};
|