4 ms·
> Because your JavaScript code will be part of the request/response path, it must be lean, mean, and self-contained. It cannot make calls to other web services
by hackcrafter 10y ago
> Because your JavaScript code will be part of the request/response path, it must be lean, mean, and self-contained. It cannot make calls to other web services and it cannot access other AWS resources. It must run within 128 MB of memory, and complete within 50 ms.
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...
- ash_gti 10y agoCouldn't you have your apps primary routing handling in this?
- forrestbrazeal 10y agoThe blog post says that one of the primary use cases is to help preview content show up correctly on Facebook, etc. So I don't think client-side routing for static apps will work in this case.
- mifreewil 10y agoThe linked post uses CloudFront as an example, which is commonly used simply as a CDN in front of static content on S3. This allows you to take that model and add some dynamic content to it. 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.
- Alex3917 10y ago> I'm having a hard time conceptualizing what kind of logic you would run on these edge functions? 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.
- jensvdh 10y agoWould you be able to route facebook/google to a pre-rendered version of your app without sending it a 301 redirect though?
- jalk 10y agoThis is totally cool if the origin is just a dumb S3 bucket. From what I can tell, you can implement the same kind of rewrite logic you would otherwise have in i.e. httpd/nginx conf. And of course doing so at the edge means that you potentially shave off some latency during redirects.
- wiredfool 10y agoIt's a potentially cleaner way to send back a redirect from API gateway/lambda rather than pattern matching on http in the error string of the Jason response body.