Lambda@Edge – Preview
aws.amazon.com
aws.amazon.com
I've been waiting for months for re:invent in the hope that it would be announced today, only to be disappointed. I'm not the only one in this situation: stuck on Python 2.7, hitting issues left and right because of an ancient runtime that we no longer would care about were it not for Lambda.
Just today I hit another issue in production which impacted our webhook system. Wouldn't you know it, `json.dumps()` produces illegal json in Python 2.7 when you give it an IntEnum:
>>> from enum import IntEnum; from json import dumps, loads
>>> class E(IntEnum):
... A = 1
>>> dumps(E.A)
'E.A'
>>> loads(dumps(E.A))
Traceback (most recent call last):
...
ValueError: No JSON object could be decoded
Please. Do something about this. It's wasting so much time :(That being said, re: Python 3, you should keep a close eye on Zappa (https://github.com/Miserlou/Zappa) - as we've got a surprise in store that may delight you!
Thank you for making it though. It's a really cool part of the Lambda ecosystem. Excited to hear there's something in store for Py3 :)
It would be pretty simple to wrap this up and automate it easily using a Terraform file. All it requires is an S3 resource for the ZIP, a Lambda resource using the S3 resource for the code, and finally an API Gateway resource to tie it all together.
Thoughts?
We already use CloudFormation under the hood for the API Gateway, though to be honest I'm seriously considering moving away from it because it's so fickle.
There are also some security disadvantages and other problems from using CloudFormation for maintaining Lambda functions, plus you lose out on all the extensive functionality we provide. We're pretty damn well battle tested to avoid that stuff now.
What you're offering is awesome, for the record. I think it's a good idea, I think it's powerful, I think it's fast. It's a good idea and you should keep working on it.
However, it's a single, small Terraform file worth of work from my perspective.
Looks like you have to jump through a couple of hoops but that might work for running Python 3.
In fact, if the promised ability to read/write the request/response bodies does appear, it might be possible to deploy your entire website or app as a single Lambda@Edge function. (Not every app would fit within the size, memory, and CPU constraints, of course.)
The main limitation would probably be the fact that for each incoming HTTP request, your choices are limited to either making zero origin requests (i.e. the function generates the response directly) or one origin request. It's not clear how this could work if you wanted to make two origin requests and combine them to render a single response.
I'm totally going to sign up for the preview and play around with it! Especially if, like the regular node.js Lambda functions, you can include arbitrary Linux binaries with the function code. Compiled request-processing code would easily meet the 128MB/50ms criteria.
https://news.ycombinator.com/item?id=13011120
This should definitely meet our needs in both cases: serving prerendered content when necessary, and also adding the security headers to the front end. And it's definitely a 10x better solution than having an extra EC2 instance with your private certs on it, just to run an nginx proxy with twenty lines of code.
It was in the pipeline already I guess.
I'm having a hard time conceptualizing what kind of logic you would run on these edge functions?
You have access to headers, so also things like client cookies, so could you use that to potentially personalize/templatize the body (once they have body mutation abilities)?
Or is it really just about static content routing? Detect google bot user agent and send them to resource A versus B etc...
I just recently used this model to host a JS widget used on external websites, now I could for example add some basic logic to disallow certain domains (by checking referrer headers) from using the widget.
Two use cases:
1) Routing Facebook and Twitter to a pre-rendered version of your single page app based on their user agents.
2) Adding custom headers to your responses, e.g. for a Content Security Policy.
There is no good way to do either of those things currently. You could have one off options for each of those and the 50 other common use cases, but this is actually a really elegant solution. Very well done.
And of course doing so at the edge means that you potentially shave off some latency during redirects.
(you could use the prerendercloud npm middleware from the lambda edge)