express-lambda
Version:
Make AWS lambda behave like an express app
119 lines (102 loc) • 4.25 kB
JavaScript
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Node = require("./node");
var Resource = require("./resource");
var async = require("async");
var ApiGateway = require("./api_gateway");
var Lambda = require("./lambda");
var Table = require("cli-table");
var _ = require("underscore")._;
var Application = function (_Node) {
_inherits(Application, _Node);
function Application() {
_classCallCheck(this, Application);
return _possibleConstructorReturn(this, Object.getPrototypeOf(Application).call(this, null, "", ""));
}
_createClass(Application, [{
key: "make",
value: function make(parent, fullpath, path) {
return new Resource(parent, fullpath, path);
}
}, {
key: "name",
value: function name(_name) {
this._name = _name;
}
}, {
key: "build",
value: function build(done) {
async.series([this._buildApiGateway.bind(this), this._buildChildResources.bind(this), this._buildLambdas.bind(this), this._integrateLambdas.bind(this), this._deployApiGateway.bind(this), this.print.bind(this)], done);
}
}, {
key: "resourceId",
value: function resourceId() {
return this._apiGw.rootResourceId;
}
}, {
key: "makeLambda",
value: function makeLambda(config) {
return new Lambda(config);
}
}, {
key: "print",
value: function print(done) {
var table = new Table({
head: ["Methods", "Path", "Lambda"]
});
for (var k in this.children) {
this.children[k].print(table);
}
console.log("Deployed!");
console.log(table.toString());
done && done();
}
}, {
key: "_buildApiGateway",
value: function _buildApiGateway(done) {
this._apiGw = new ApiGateway(this._name);
this._apiGw.build(done);
}
}, {
key: "_deployApiGateway",
value: function _deployApiGateway(done) {
this._apiGw.deploy(done);
}
}, {
key: "_buildChildResources",
value: function _buildChildResources(done) {
var _this2 = this;
var tasks = _.values(this.children).map(function (c) {
return function (done) {
c.build(_this2._apiGw, done);
};
});
async.series(tasks, done);
}
}, {
key: "_buildLambdas",
value: function _buildLambdas(done) {
var tasks = _.values(this.children).map(function (c) {
return function (done) {
c.buildLambda(done);
};
});
async.series(tasks, done);
}
}, {
key: "_integrateLambdas",
value: function _integrateLambdas(done) {
var tasks = _.values(this.children).map(function (c) {
return function (done) {
c.integrateToLambda(done);
};
});
async.series(tasks, done);
}
}]);
return Application;
}(Node);
module.exports = Application;
;