News for hackers. Stuff that matters.
Re:AWS Lambda Web Adapter by paulgb on Saturday June 22, 2024 @03:35PM (#40761545)
One word of caution about naively porting a regular web app to lambda: since you’re charged for duration, if your app does something like make an API call, you’re paying for duration while waiting on that API call for each request. If that API breaks and hangs for 30s, and you are used to it being (say) a 300ms round trip, your costs have 100xed.

So lambda pricing scales down to cheaper than a VPC, but it also scales up a lot faster ;)

Re:AWS Lambda Web Adapter by mlhpdx on Saturday June 22, 2024 @03:41PM (#40761584)
Not untrue, but also not true. It isn’t a Lambda problem, It’s the problem of running the same old, same old code on lambda.

Running clusters of VM/container/instances to “scale up” to transient demand but leaving largely idle (a very, very common outcome) then an event oriented rewrite is going to save a big hunk of money.

But yeah, if you keep every instance busy all the time, it is definitely cheaper than lambda busy all the time.

Re:AWS Lambda Web Adapter by paulgb on Saturday June 22, 2024 @03:46PM (#40761614)
Sure, if you’re willing to rewrite for an event-based architecture you can avoid the problem, but the post is a framework designed for running on Lambda without that rewrite. One of the stated goals is to have the same container run on EC2 or Fargate.
Re:AWS Lambda Web Adapter by zoover2020 on Saturday June 22, 2024 @03:56PM (#40761678)
A lot of internal web apps with low TPS can be easily ported to Lambda using these adapters. They should be the main use case IMO.
Re:AWS Lambda Web Adapter by allannienhuis on Saturday June 22, 2024 @05:01PM (#40762178)
A lot of internal web apps with low TPS can easily be run on a $5-30/month vps.
Re:AWS Lambda Web Adapter by easton on Saturday June 22, 2024 @06:44PM (#40762896)
The minimum cost of running a task on Fargate is under a dollar a month. If you’re a AWS company, you can get cheaper if you take the lock in (not that there’s much lock-in with Fargate)
Re:AWS Lambda Web Adapter by mlhpdx on Saturday June 22, 2024 @03:55PM (#40761667)
I understand the point. It’s one in a long line of such enabling tech — all leading to the same outcome.
Re:AWS Lambda Web Adapter by parthdesai on Saturday June 22, 2024 @03:56PM (#40761673)
> Running clusters of VM/container/instances to “scale up” to transient demand but leaving largely idle (a very, very common outcome) then an event oriented rewrite is going to save a big hunk of money.

If you're using k8s, HPA is handled for you. You just need to define policies/parameters. You're saying as if rewriting an entire app doesn't cost money.

Re:AWS Lambda Web Adapter by danappelxx on Saturday June 22, 2024 @04:25PM (#40761901)
This is an interesting point. Hangs usually cost $ from user experience, with serverless they cost $ from compute. All the more reason to set strict deadlines on all API calls!
Re:AWS Lambda Web Adapter by hn_throwaway_99 on Saturday June 22, 2024 @08:49PM (#40763657)
> All the more reason to set strict deadlines on all API calls!

I've seen this backfire in production though. E.g. suppose there was a 5 sec limit on an API call, but (perhaps unintentionally) that call was proportional to underlying data volumes or load. So, over time, that call time slowly creeps up. Then it gets to the 5 sec limit, and the call consistently times out. But some client process retries on failure. So, if there was no time limit, the call would complete in, say, 5.2 seconds. But now the call times out every time, so the client just continually retries. Even if the client does exponential backoff, the server is doing a ton of work (and you're getting charged a ton for lambda time), but the client never gets the data they need.

Better in my opinion to set alerts first.

Re:AWS Lambda Web Adapter by johtso on Saturday June 22, 2024 @04:44PM (#40762042)
That's one thing that's really nice about Cloudflare workers, you're billed on CPU time, not duration, so you can happily make slow requests to other services.
Re:AWS Lambda Web Adapter by throwAGIway on Saturday June 22, 2024 @04:47PM (#40762074)
How does that work? How can they determine my execution time is spent waiting and not processing?
Re:AWS Lambda Web Adapter by CaliforniaKarl on Saturday June 22, 2024 @05:01PM (#40762183)
When a Linux process is waiting for a socket to have data ready to read (using a system call like select, poll, or epoll), that process is put into a sleep state by the kernel. It continues accruing “wall-clock time” (“wall time”) but stops accruing CPU time. When the kernel has data for the socket, the process starts running again.

The above tracking method works for containerized things. For virtualized things, it’s different: When a Linux system has nothing to do (all processes sleeping or waiting), the kernel puts the CPU to sleep. The kernel will eventually be woken by an interrupt from something, at which point things continue. In a virtualized environment, the hypervisor can measure how long the entire VM is running or sleeping.

Re:AWS Lambda Web Adapter by throwAGIway on Saturday June 22, 2024 @05:06PM (#40762212)
Thanks to you and the others who replied too, very insightful. You put me on the right track to learn more about this, much appreciated.
Re:AWS Lambda Web Adapter by btown on Saturday June 22, 2024 @09:45PM (#40763964)
Economically, Cloudflare can do this because they only need a V8 isolate per instance (so barely any RAM besides instantiated JS objects), whereas a Lambda needs RAM for the entire runtime environment. So many more customers can run on the same machine, even if many are waiting on I/O simultaneously.

https://blog.cloudflare.com/cloud-computing-without-containe...

Re:AWS Lambda Web Adapter by paulgb on Saturday June 22, 2024 @04:55PM (#40762138)
They use their own runtime for V8 isolates, so they have a lot of leeway into how they measure/meter it.
Re:AWS Lambda Web Adapter by navaati on Saturday June 22, 2024 @04:57PM (#40762154)
At the most basic level, your process is in the D or S states rather than R state. Cloudlflare workers are not exactly Unix processes, but the same concept applies.
Re:AWS Lambda Web Adapter by chuckadams on Saturday June 22, 2024 @05:05PM (#40762207)
Lambdas have a timeout, which defaults to 3 seconds.
Re:AWS Lambda Web Adapter by OJFord on Saturday June 22, 2024 @06:19PM (#40762720)
And maxes at 30s (if apigw triggered), GP's point totally valid.
Re:AWS Lambda Web Adapter by coredog64 on Sunday June 23, 2024 @12:54AM (#40764912)
Used to be a hard quota of 29 seconds for APIGW, but within the last month AWS has updated that to a soft quota. You will have to trade off concurrent calls for the longer APIGW timeout though.
Re:AWS Lambda Web Adapter by datashaman on Sunday June 23, 2024 @01:01AM (#40764933)
Use ALB - no limitations on request time.
Re:AWS Lambda Web Adapter by chuckadams on Sunday June 23, 2024 @01:12AM (#40764974)
Well, the point is you want a short timeout if your lambda is hanging and you're being billed by the second. If you're not setting it explicitly when you deploy, you're more or less writing Amazon a blank check.
Re:AWS Lambda Web Adapter by foundart on Saturday June 22, 2024 @05:16PM (#40762293)
Interesting. It makes me wonder about designing "lambda-client-friendly APIs".

To reduce the chances of being long-running, the api would be async, meaning: the client makes a request and gets a claim code result quickly, with the api host to process the request separately and then make a callback when done.

Lots of issues to consider.

Anyone have experience doing this? Would be great to hear about it.

Re:AWS Lambda Web Adapter by mike_d on Saturday June 22, 2024 @05:31PM (#40762392)
> It makes me wonder about designing "lambda-client-friendly APIs"

If your hammer fails to drive a screw into wood, you don't need to contemplate a new type of low friction wood.

Re:AWS Lambda Web Adapter by krick on Saturday June 22, 2024 @05:48PM (#40762503)
Or maybe you do, if screws are so much cheaper than nails.
Re:AWS Lambda Web Adapter by chuckadams on Saturday June 22, 2024 @05:43PM (#40762465)
Sounds like webhooks to me -- a use case Lambda excels at.
Re:AWS Lambda Web Adapter by foundart on Saturday June 22, 2024 @06:47PM (#40762926)
Thanks! I think you're right.

To go beyond my original question:

In terms of how I have thought about them before, webhooks are similar, but not quite the same thing. I've really only dealt with webhooks when the response was delayed because of a need for human interaction, for example: sending a document for e-signature and then later receiving notifications when the document is viewed and then signed or rejected.

I haven't experienced much need to make REST APIs async, only in cases where the processing was generally always very slow for reasons that couldn't be optimized away. I haven't seen much advocacy for it either.

However, if we think about lambda-based clients, then it makes a lot more sense to provide async apis. Why have both sides paying for the duration, even if the duration is relatively short?

update:

Whether or not it's cheaper for the client depends on the granularity of the pricing of the client's provider. For AWS, it seems to be per second of duration, so async would be more expensive for APIs that execute quickly.

Re:AWS Lambda Web Adapter by coredog64 on Sunday June 23, 2024 @12:58AM (#40764927)
I did this for a client using APIGW and DynamoDB. The claim check is the key, and then there’s a polling endpoint in APIGW that goes directly to DynamoDB with no Lambda in between. When the claim check is processed, the location of the data is an additional attribute in DynamoDB and the APIGW/DynamoDB integration sends an HTTP 302 with the final result URL.
Re:AWS Lambda Web Adapter by jmull on Saturday June 22, 2024 @05:25PM (#40762352)
I think "a regular web app" is interactive...

3s would rarely be acceptable, much less 30s. Not that it never happens, but it should be rare enough that the cost of the lambda isn't the main concern. (Or if it's not rare, your focus should be on fixing the issue, not really the cost of the lambdas.)

Anyway, I think you'd typically limit the lambda run time limit to something a lot shorter than 30 sec.

Re:AWS Lambda Web Adapter by multani on Saturday June 22, 2024 @05:46PM (#40762483)
What is the pattern to use on Lambda if you actually have to call out other services, which may, sometimes, take a long time to answer? Do you make requests with a shorter timeout and have your Lambda fail when it triggers? Do you delegate long calls to a non-Lambda service?
Re:AWS Lambda Web Adapter by moribvndvs on Saturday June 22, 2024 @06:16PM (#40762695)
In a case where a dependency has a consistent high latency and you can’t avoid it, I’d run the numbers and see if it’s more worthwhile to just run your app on ECS or something instead.
Re:AWS Lambda Web Adapter by Aeolun on Saturday June 22, 2024 @10:20PM (#40764174)
I find that running your app on ECS is generally a great way to just do away with a whole class of problems. I’ve never found lambda to do away with any of the issues I encounter on ECS.
Re:AWS Lambda Web Adapter by moribvndvs on Sunday June 23, 2024 @10:48AM (#40767835)
I don’t feel great about lambda (outside of jobs processing and such) as it sometimes feels like you took your application and broke it into a thousand little footguns where a mistake or bad actor can tank your business, but if your company experiences very spikey workloads or not enough income to pay for 24/7 ECS and such, I can see the appeal.
Re:AWS Lambda Web Adapter by dragonwriter on Saturday June 22, 2024 @06:30PM (#40762791)
If you have enougu volume to warrant it, probably re-architecting the lambdas so the before/after part of the calls is a separate invocation, with an adapter service living on ECS that gets a call from the “before” lambda, handles the remote request and response, the calls the “after” lambda with the response.

The simpler solution is often to just lift the app from lambda to ECS without internal changes

Re:AWS Lambda Web Adapter by roncesvalles on Saturday June 22, 2024 @06:09PM (#40762636)
It seems like Lambda is not suited for such "hanging" use cases. To me the best use case for Lambda is for an API call that might be made very infrequently, like say 50 times a day. Doing the same with a VM instance (remember, it has to be HA, secure etc) is probably not worth the effort.
Re:AWS Lambda Web Adapter by throw156754228 on Sunday June 23, 2024 @03:21AM (#40765406)
There are AWS step functions that might fit this use case. Just another product AWS will charge you to use to perpetuate the serverless myth.
Re:AWS Lambda Web Adapter by OJFord on Saturday June 22, 2024 @06:21PM (#40762734)
A corollary is that if you have your lambdas call your other lambdas call...
Re:AWS Lambda Web Adapter by thefourthchime on Saturday June 22, 2024 @06:56PM (#40762994)
lambda blocking on calling other lambdas is a bit of an antipattern.

If it can be avoided and use something like sqs to call the other lambda, die and then resume on a notification from the other lambda.

That can tricky, but if costs are getting bad it’s the way.

Re:AWS Lambda Web Adapter by OJFord on Sunday June 23, 2024 @11:19AM (#40768081)
Absolutely. Wasn't saying it's a good idea.
Re:AWS Lambda Web Adapter by thefourthchime on Saturday June 22, 2024 @06:58PM (#40763001)
I've done an internal website using lambdas. It works fine, I just use jinja2 templates and load html files that are part of the deployed file system.

Any other logic is just normal SPA stuff.

If you set the min concurrency to 1 it's pretty snappy as well.

Re:AWS Lambda Web Adapter by leef on Sunday June 23, 2024 @12:45AM (#40764867)
That is kind of the point of this repo. If your API implementation is too expensive for lambda move the same container to run on EKS/ECS fargate or ec2. The opposite holds as well - if you can save money by moving it from fargate to lambda then you can use the same container.
Re:AWS Lambda Web Adapter by okigan on Sunday June 23, 2024 @01:24AM (#40765004)
As @leef mentioned, you should transition between Lambda and <another offering> based on the current load.

I've published LambdaFlex as an Infrastructure as Code (IaC) template. It automatically scales and manages traffic between AWS Lambda and AWS Fargate [1].

This setup leverages the strengths of both services: rapid scaling, scaling down to zero, and cost-effectiveness.

[1] GitHub: https://github.com/okigan/lambdaflex