Ask HN: How has your experience with AWS Lambda been?
I've been thinking about trying out AWS Lambda for my next project and would just like to survey the community: how are you currently using Lambda (i.e. current setup, the product, etc)? How has the cost, performance, and scalability been? Any issues or deal-breakers? Would you use Lambda for your next project?
Thanks!
22 comments
[ 3.1 ms ] story [ 53.6 ms ] threadUsage: Algorithmic trading, Alexa voice apps, Brokerage price matching
http://KloudTrader.com
[1] https://docs.aws.amazon.com/lambda/latest/dg/limits.html
The paradigm I use is that of treating Lambda as "glue" between services, and it has worked out amazingly well for that. Quick invocations, seemingly infinite scaling. CW logs (monitoring) could be better, but tools like Apex help with parsing them.
I can write the functions in any one of the languages that are supported and they are all interlace-able through an interface. If I need to use ML and prefer python libraries, I can do that and call python from a nodejs function or vice-versa. All this without having to worry abt keeping a server up and secure and scaling.
There are issues with loading times and cost, but easily the best thing that happened for me as a single dev proving out a product MVP.
Some random thoughts and gotchas in no particular order:
1. Don't do your own deployments. Use Serverless.js (https://github.com/serverless/serverless). It's in JS but that doesn't lock you into the nodejs lambdas, it can deploy to any of the runtimes.
2. Use Zappa if you want to host a "serverless website". But frankly, serverless websites are only for hobby projects right now.
3. CPU vs Memory scaling sucks. You have to scale both at once; you can't do high CPU/low memory. This hurts the wallet for compute-intensive tasks.
4. 5-min hard timeout on all functions. Don't use Lambda for long-running tasks.
5. Low-CPU lambdas (128MB tier) are terrible at cold starts if you have lots of stuff to import (which WILL BE THE CASE for Zappa applications!). If a cold start exceeds your timeout (which defaults to 30 sec), your Lambda will never complete and never get out of cold start.
6. If you're playing with S3, PUTs will hurt your wallet. A common application of Lambda (the famed "resize images" example) has a workflow that looks like this: GET on API gateway, PUT to s3, triggers an event which fires a Lambda, lambda processes payload, PUTs result back to S3. If processing your payload is fast, the PUTs in this case could be the most expensive part of your flow.
7. X-Ray is atrociously confusing.
8. No cloudwatch metrics for memory usage. Had to do my own using log metrics. Dumb.
9. There's a cool versioning system for the code artifact, kinda like ECS has. It's really nice to use except that unlike ECS it doesn't have native lifecycle rules, which means you have to do your own cleanups. Dumb.
10. Lambda patterns can be implemented more cheaply and more efficiently using tasks queues and autoscaling EC2s. Amazon's "efficient" compute allocation is outweighed by the margins on Lambda pricing. As with other Amazon services, you're paying for the system to be managed.
11. Aurora Serverless is super interesting, but FWICT nowhere near ready for prime time.
12. API gateway is a solution looking for a problem. If you have to use it (eg. you must trigger your lambda through an http request and you don't want to run a web server), use it in proxy mode.
13. Golang lambdas are very promising. I want to try them out.
14. There's a native canary system in Lambda/APIGW nowadays. Also want to try it out. Had to roll my own before it existed and now too scared to touch the production system.
15. If you hit concurrency issues, your problem might not be load, it might be throughput. Is your DB slower than usual? Common pattern: Increase in Lambda requests hitting your DB, slows your DB down, which in turn slows your lambdas down, which causes you to hit concurrency limits. All these metrics are tightly related.
16. Your tests should not assume a Lambda environment unless your app actually depends on the lambda environment (it generally shouldn't).
17. Use this thing: https://github.com/lambci/docker-lambda - Among other things, you can use it to build binary libs/dependencies you want to run on Lambda (cairo for example).
18. Use this thing: https://github.com/spulec/moto -- And also this thing: https://github.com/localstack/localstack
19. Cloudwatch logs suck. If you want your app to be debuggable, make sure you know how to find logs ...
- You have a mostly static site that needs a couple of dynamic views (eg. comment or payment processing), but the site doesn't get enough traffic to put a webserver behind it.
- You are continuously processing sub-5min tasks and don't want to have to be doing the up/down scaling yourself and you're willing to pay a premium to have the scaling be managed.
- You want an easy way to run a piece of code from various AWS triggers without having to set up webhooks in between.
- Your next employer is a buzzword vulture and you have an idea for a serverless virtual reality blockchain.
Another case we've had success with is transforming and relaying webhooks from different services (relaying events into Datadog for services that don't have a native integrations) or acting on occasional webhooks that don't happen too often (creating a default set of labels on a new Github repo).
If you're doing anything asynchronously, it's pretty nice. Be aware that the amount of memory you allocate to your functions is directly proportional to the CPU amount (and price) you're given. There's also the caveat that invocations perform _at least once_ but not necessarily once. A few months ago we saw a significant increase in repeat lamdaba invocations/retries even when the original execution was successful.
So far I think the development process has been good. Deployment has been okay, and I’ve found it easier to deploy my .NET functions vs the old Go functions.
Logging/debugging is a bit of a chore but not awful. Cloudwatch alarms are fairly useful for knowing when something critical happened, but you still have to dig in fairly deep to find the relevant error information.
Performance wise, Go was really fast even with the smallest amount of memory. Cold starts were around 1s and requests after that were around 30-40ms on average. C# is substantially slower unless you bump up the memory.
All that being said, overall I really enjoy developing Lambda functions and not having to worry about containers, etc., because I’m not a DevOps person. I would definitely use it again for other projects, and probably will.
Something to note, latencies decrease with increased usage due to fewer cold starts. I've seen latencies as low as 17ms in our busiest region with ~40ms in less busy regions.
Lambda app: just keeps chugging. GAE app: perpetual disaster.
As a HTTP endpoint, the cold-start is a pain, but after I'm getting answers in 10-20 milli-seconds. You may contact me directly to tell you how to go around this cold-start issues.
All endpoints/operations exposed through API Gateway.
Thought it would be a lot simpler to set up than it was. It's pretty convoluted doing API Gateway -> Lambda, especially when you make changes.
I had thought it would be way simpler. single click define endpoint, then just write some code.
The AWS UI most definitely got in the way trying to accomplish this.
Only real downside so far is there can be some spin-up delay of a couple of seconds for the first consumer of your API. Not a big deal in my scenario of mainly a backoffice type app.