AWS Lambda Edge changes duration billing granularity from 50ms down to 1ms
aws.amazon.com
aws.amazon.com
For those who aren't super familiar with AWS, this announcement only covers "Lamda@Edge", this isn't the "normal" Lamda serverless function service. These are Lamda functions running at AWS Edge Locations, which are hundreds of CDN endpoints around the world. Lamda@Edge have various restrictions on what they can do, compared to the main Lambda service. They can only be triggered by CloudFront (AWS' CDN service). You could think of them as a "lite" version of Lambda. They are generally used for basic tasks like renaming/manipulating HTTP headers coming into the CDN. So they tend to run in just a few milliseconds.
Normal Lambda are currently billed in 100ms increments. But it would be great to see this come down. I run a few Lambda functions that take < 10ms to run and it would be nice to be able to get 10x the invocations than I am getting on them now because I have to pay the 100ms rate for a 10ms invocation. Granted its all so cheap, even at scale, that its hard to complain too much.
Lambda actually reduced their billing granularity to 1ms at Re:invent 2020. if anything, Lambda Edge is trailing :).
Been 1ms for a few months now. =)
For instance, Cloudflare throws in fair-use bandwidth and its cache for free, while there's also no need to setup an API Gateway to serve http reqs (if forwarding http is all you're doing with apigw).
I'm not knowledgeable AT ALL in this area, having never used or first-hand seen these FAAS things.
But header manipulation? Really... These are executed as aws lambdas?! I don't get why you'd ever need to do this.
(Not being facetious, honest puzzlement!)
Then why a (Turing-complete) programming language and not a config language? Simple: because a programming language gives you infinite more power than what any config system could ever provide. E.g. I could compare the origin IP, determine the country, and change the response based on that. And there are plenty of use cases like this which you cannot express in a config language.
Well, you can do that in plenty of "config languages", including nginx[1]. The reason Lambda exists is that it's good for Amazon, because they can push all the costs of the logic back onto the customer. (It could also be good for the customer, in that whatever configuration Amazon might otherwise support could be limited.)
[1] http://nginx.org/en/docs/http/ngx_http_geoip_module.html
Cloudfront is a CDN, it's not intended to be a replacement for nginx.
From a customer point of view, maybe you need to rewrite the path based on the contents of a cookie, or maybe you want to shed certain types of requests in high load scenarios, or maybe there's a buggy upstream application that sends bad cache-control headers, or ...
If the goal is to let the customer specify infinitely complex logic at the edge, a programming language is a good way to do that. Function As A Service is a good billing model for lots of invocations of short, small functions across the customers choice of language.
We experimented with using Lambda@Edge for manipulating a header, but the added latency just wasn't worth it, and we had to come up with a different solution. That was years ago though, so maybe it is better now.
but by allowing JS/whatever, it gives you an infinite landscape to work with the values in a language that a wide range of people grok.
it's just a matter of getting a decent deployment setup so you can rinse and repeat easily.
but i agree, it's a freaking jack hammer where most people need a small tack hammer.
Some of the stuff we do: - rewrite urls - auth and permissions check - serve index.html on directory indexes - inject dynamic content in served html files - add CORS headers
> When you’re working with the HTTP response, Lambda@Edge does not expose the body that is returned by the origin server to the origin-response trigger. You can generate a static content body by setting it to the desired value, or remove the body inside the function by setting the value to be empty. If you don’t update the body field in your function, the original body returned by the origin server is returned back to viewer.
https://docs.aws.amazon.com/AmazonCloudFront/latest/Develope...
> If you are using an AWS origin, effective December 1, 2014, data transferred from origin to edge locations (Amazon CloudFront "origin fetches") will be free of charge.
And in general data out from CloudFront ($0.085 to $0.02 in NA & EU) is cheaper than data out from S3 ($0.09 to $0.05 in us-east-2). For the lambda@Edge portion it's $0.60 per 1 million requests while the CloudFront requests are $0.75 to $1.00 per 1 million requests.
Those are public on demand rates and any customers with significant or consistent usage should definitely contact AWS for lower committed/custom prices.
Edit: Disclaimer I'm a principal at AWS, and in the past spent significant time working on CloudFront & Lambda@Edge, but all of the above is public information.
These are executed. Lambda is just a brand name. We did this 15 years ago on hardware load balancers, proxy servers, cache servers etc
This makes lambda's the glue of AWS. The input events are small json values, and the outputs are json values, and you can (mostly) use any language you want.
In that phase you can change anything about the request itself, or the origin it will connect to. But the function only needs to run when there's a cache miss.
I have an application that needs to select an origin based on the request path (too many to use CloudFront cache behaviours), with a cache miss rate of less than 1%. It's a tiny amount of additional latency for cache misses, and a very small proportion of our CDN costs per month.
I caught it too. I get downvoted a lot for not following rules and I don’t really care this was hilarious
I have been thinking about this for a while as it would avoid having cloudfront making a origin call to the backend server for db reads on data that does not change frequently. I am trying to figure out why this is a bad idea .
For origin-requests you get 50MB. See https://docs.aws.amazon.com/AmazonCloudFront/latest/Develope...
And "The same Lambda execution environment may be reused by multiple Lambda invocations to optimize performance. The /tmp area is preserved for the lifetime of the execution environment and provides a transient cache for data between invocations. Each time a new execution environment is created, this area is deleted."
https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-...
https://aws.amazon.com/blogs/compute/choosing-between-aws-la...
Regular Lambda (not edge) are just container images up to 10 GB in size.
There's also the layers thing. A function can use up to five layers at a time. The total unzipped size of the function and all layers can't exceed the unzipped deployment package size limit of 250 MB. Can update separately from the container, almost as fast as a regular fs.
And finally it has access to EFS which is faster than S3.
Cache invalidation is tricky. Avoid it by ttl-expiring caches as frequently as budget allows. We, instead, employ a (probably over-engineered) hand-rolled set-reconciliation algorithm to match our read/write patterns.
How likely are you to see 1ms execution times for this stuff tho? Super simple logic should be that low I guess..
They must have a very mature execution environment to be able to offer this (if 1ms execution is achievable), cf workers have a whole set to logic to average out cpu spikes so you don’t randomly hit the 50ms limit, bc their execution of your code isn’t that deterministic I suppose.
The firecracker microvm says startup time is under 125ms, but I have not personally done any benchmarking, though my employer does use firecracker for hosting our CI builders.
Still faaairly generous, good luck getting 50 sub requests done in 50ms if you had to measure against wallclock =)
The lamda@edge function is executed only once but you decide when - before or after the cache and either on the request or response.
Can I maintain state between inbound request->origin request->origin response->inbound response?
My understanding was you can’t and it got called 4 times with different events, workers solves this by you being responsible for making the origin request (there is a simple mode where it does it for you to) with promises to manage origin response and inbound response logic.. I thought lambda@edge didn’t work like that?
If you wanted to maintain state then I'd guess the easiest (only?) way is for the function to add headers to the HTTP request/response as it passed through.
I've been meaning to do a write up on it and probably should, but feel free to check it out in action at the site I'm developing https://sqwok.im
There's a fastboot meeting next week that should be good as well https://www.eventbrite.com/e/ember-fastboot-ssr-beyond-ticke...
Yep Sqwok is rendered with fastboot (mostly used for the post page seo/rich preview) Feel free to ping me @guac or ask a question and I'll respond, and also there is a fastboot meeting next week that I'll be at and it should be interesting! The fastboot team has been working on some really cool stuff.
https://www.eventbrite.com/e/ember-fastboot-ssr-beyond-ticke...
Isn't this guaranteed to lower the price for *all* Lambda@Edge functions? What is the case where it wouldn't result is a <= cost?
Edit: Assuming even distribution of run times within each 50ms chunk - I guess maybe that's a bad assumption.
Are there any examples of AWS ever having done this? Personally I don't recall any, but would be interested to know!
The only instance I can find of any cloud provider increasing prices was once in 2015 when Microsoft did in Europe...and while that led to a flurry of "cloud providers are going to increase prices" blog posts and things, calmer heads noted the exchange rates as the likely reason (and, certainly, the claims that prices would increase across the board never came to pass).
Maps API's I think went up pretty big time on google side.
There were even several posts on HN around that time period of personal projects (maybe even companies) going under because of the price change.
https://geoawesomeness.com/developers-up-in-arms-over-google...
That plus shutdowns of things - google is not most stable
> ... When we launched S3, we were charging only for data transfer and data storage. It turned out that we had quite a few customers who were storing millions and millions of thumbnails of products they were selling on eBay. There was not much storage because these thumbnails were really small, and there wasn't much data transfer either, but there were enormous numbers of requests. It made us learn, for example, when you design interfaces, and definitely those you charge for, you want to charge for what is driving your own cost. One of the costs that we didn't anticipate was the number of requests, and request handling. We added this later to the payment model in S3, but it was clearly something we didn't anticipate. Services that came after S3 have been able to learn the lessons from S3 itself.
Ref: https://m-cacm.acm.org/magazines/2021/3/250706-a-second-conv...
From a financial perspective, isn't this basically raising prices over time?