From Express.js to AWS Lambda: Migrating Existing Node Apps to Serverless
hackernoon.com
hackernoon.com
const awsServerlessExpress = require('aws-serverless-express');
const app = require('./app');
const server = awsServerlessExpress.createServer(app);
exports.handler = (event, context) => (
awsServerlessExpress.proxy(server, event, context)
);
It's really convenient to be able to develop simple APIs using Express, and then to expose them via Lambda functions using aws-serverless-express. After you've done it once or twice, it's really easy to throw together single-purpose APIs and deploy them in a matter of minutes. For example, I was recently frustrated with the fact that CircleCI's API for accessing build artifacts is perpetually broken, and I wrote a little microservice to expose the same functionality [2]. It's definitely awesome to be able to deploy one-off projects like that without needing to worry about any sort of server maintenance. time curl -L 'https://circleci.intoli.com/artifacts/intoli/exodus/coverage-report/total-coverage.json'
which outputs something like the following (the timing will vary a bit obviously). { "coverage": "92.43%" }
real 0m0.798s
user 0m0.046s
sys 0m0.010sfor reasons that I've explained in a README section https://github.com/tobiipro/http-lambda#a-word-on-httpsgithu...
Your snippet becomes
const {httpLambda} = require('http-lambda');
const app = require('./app');
exports.handler = httpLambda((http, _event, _context) => (
http.createServer(app);
));This looks very cool, but seems ripe for some ugly emergent behavior to appear.
I run a web hosting service, and while my application code is a bit more complicated now, I don't have to worry about monitoring ec2 instances, process managers, and that's worth it. That particular trade of is worth it.
If you manage an application with a high level of application logic, such that keeping servers alive is relatively simple, maybe the calculus works out differently.
Many concerns are removed from my application code and build and deploy systems by Lambda and API gateway.
You just throw some zip files in S3 and you have a web service.
No more image registry, container orchestration, load balancers, AMIs, autoscaling, etc.
You also get to remove things code around CORS, auth, polling etc. from your app.
I have a bunch of writing on how FaaS makes things easier here:
Here is a project to enhance the lambda experience with webpack https://github.com/serverless-heaven/serverless-webpack/blob...
In production you would probably want to minify and micro-optimize anyways, so why pick one of the standard build pipeline tools and get async/await also?
Your last option is spotinst. If you use their serverless service, you get native access to node 8. They load balance across AWS EC2s, GCE, and Azure.
^ why _not_ pick ...
Good question, and thanks for the link
I read it should be used for data transformatiom and computation and not transportation.