[9/23] This project is now obsolete. If you're interested in such feature, see (https://aws.amazon.com/blogs/aws/api-gateway-update-new-features-simplify-api-development/)[API Gateway Greedy Path] [7/7] I've decided to stop further development of index.lambda
Once upon a time there was index.php.
Live Demo: [Diagnostic Page] (https://lwrnabvd4f.execute-api.us-east-1.amazonaws.com/demo) (up and running as of 06/28)
Index.lambda is a bootstrapper and lightweight web framework for building server-side web application on AWS Lambda and AWS API Gateway. AWS API Gateway was primarily designed for JSON payload. However with the right config (and contortion), the stack work well as a serverless server side web app platform.
Easy setup
import Index from "../core/index";
var index = new Index();
export default (event, context) => {
index.set(event, context);
// ...
}
Dynamic routes Define paths through code (instead of defining them as endpoints in AWS API Gateway).
export default (event, context) => {
index.get("/", function(req, res) {
//... handle request
}
index.post("/path-1", function(req, res) {
//... handle request
}
//process the request
return index.handle();
}
Paths can be 3 levels deep.
API | Example | |
---|---|---|
1 level | event.params.level1 // contact-us |
E.g. http://domain/contact-us |
2 levels | event.params.level2 // ronaldwidha |
E.g. http://domain/user/ronaldwidha |
3 levels | event.params.level3 // how-to-build-a-blog |
E.g. http://domain/article/123/how-to-build-a-blog |
Built in Mustache Template engine support
export default (event, context) => {
//...
var renderingService = new RenderingService();
return renderingService.render("mustache-view", { ... })
.then((html) => { return context.done(null, html)});
}
Or roll out your own template engine.
Get any Query Strings
export default (event, context) => {
event.query // {"query":"123"}
// or
index.req.query // {"query":"123"}
}
Perform a 302 redirect
export default (event, context) => {
//...
return index.res.redirect(url);
}
Return error/status codes
By default, you'll have access to the following error/status codes: 301, 302, 400, 404, 500
export default (event, context) => {
return index.res.status(404).send("Sorry.");
}
To be added
npm install
sls dash deploy
- Package core library as npm package
- Support for path parm E.g. "user/:id"
- Support for Cookie
- Support for fav.ico
- manual effort required to change the lambda config from node1.0 to node 4.3