I’ve seen several tutorials about using S3 + Lambda to build web apps. Would you consider building a web app entirely on Lambda (minus graphics, etc)? I’ve made Lambdas that can output simple webpages.
What would be the benefits/pitfalls of doing this?
You can do this but API Gateway makes it quite expensive compared to running an EC2 instance if you have a high volume of load. If your EC2 instance would spend most of its time doing nothing then you could save money with Lambda and API Gateway, but if you need to deal with real traffic then API Gateway starts to get real expensive.
For perspective API Gateway is $3.50 per million requests baseline (not including bandwidth charges). Meanwhile a tiny t2.micro that costs $8 per month should be able to serve many, many millions of requests per month.
The plus side is obviously you don’t have to worry about scaling anymore, and can easily go from no traffic to tons of traffic without having to worry about horizontally or vertically scaling EC2 instances. If you were running that tiny t2.micro and suddenly got a spike of interest that overloaded the machine then your web service would probably go down until you added more t2.micros or increased the size of the t2.micro to a larger size. On the other hand Lambda and API Gateway would seamlessly scale up and just start charging you more money with no intervention required.
At some high level of scale that bill from API Gateway and Lambda would get great enough your business would probably want to migrate away from API Gateway onto EC2 due to the price, and start running your own instances, though.
We do this at my company. It seems, and I could be wrong so ignore me if so, that you’re thinking the lambda call is outputting your pages and that’s not really how it goes.
It’s more of a UI and API setup. The UI and JavaScript needed to power it get served from S3 and Lambda is used as an API by your UI code.
The payloads coming from Lambda should be pretty small if you’re using it as a REST API and so the cost can outperform ec2 pretty easily.
For our use case it is significantly less expensive than running a high availability ec2 cluster and way less administrative overhead.
I would add that lambdas are still quite slow when starting from cold especially if big in size. That makes them a poor choice if you need time critical replies as it happens when you interact with a user.
We use them for all cron tasks or auxiliary task that happen following, but disconnected from user interaction, especially since they’re so easy to setup with SNS.
I’m quite excited by Fargate since it will have all the benefits I care about (no infrastructure), with all the benefits (containers that are always on/ready, isolated). Unfortunately it’s not yet available in Europe.
It’s entirely possible to serve HTML, CSS and JavaScript to the client purely via Lambda and API Gateway. It’s not exactly ideal for a number of reasons, but I’ve set it up as a POC and it works.
Yep, never said it couldn’t be done. But as you alluded, not ideal and I’d say probably not recommended.
Edit: I could see how my comment might be poorly worded and imply it’s not possible to do what you say. That wasn’t my intention, it is possible. I stick by it not really being advisable though.
Number of requests depends on the use case and volume though. Hitting a million requests a month is easy for moderately popular sites and services. I’ve worked on relatively small projects that did millions of requests a day.
Lookout for the warm-up times when using Java (several seconds). Node and Python lambdas are pretty fast to come online, but the Java ones will require some patience for the JVM to spin up.
Another thing to consider is vendor lock-in. What you build in Lambda is designed to run in Lambda. Want to move to another serverless provider or PaaS? Prepare to spend some time refactoring. Want to move to running on a VM? Same, you’re going to need to invest some time in that.
Those cases should be obvious, regardless of the complexity of the web app, and not too overwhelming if it’s a basic app. What you should be mindful of is understanding the other proprietary AWS candy that Amazon slips you. Want to front those functions with API Gateway? Want to authenticate those API Gateway calls with Cognito? Want to use DynamoDB for your doc store? It’s all easy, especially when playing within the ecosystem that Amazon makes work together nicely. But that will make it harder to extricate if you aren’t careful.
$3.50 a month? Jeez. I mean, even $3.50 a day isn’t so bad (there’s a bunch of other costs too though).
However, the majority of requests are cacheable, so in reality (simply by sitting behind CloudFront) you won’t have as many API Gateway requests as total requests…
This.. The cloud vendors are pushing big time the serverless architecture for the lock-in. Even managed services ensure the lock-in. It’s great for a start-up but companies need to quickly move away. Else, keep an eye on cloud foundry which ensures cloud vendor abstraction.