Hacker News new | ask | show | jobs
by gehen88 1897 days ago
We use Lambda@Edge to build our own CDN on top of S3 with authentication, so our customers have reliable, fast and secure data access. We use a bunch of edge lambdas which serve thousands of requests each minute, so I suspect we'll see a nice cost reduction with this.

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

2 comments

Can I ask how you're injecting dynamic content in served html files? My understanding was that lambda@edge functions could not modify the origin response body.

> 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...

It sounds to me like they might be creating the response from scratch rather than modifying an existing one. And since they’re talking about serving data from s3, maybe it’s just a nicely formatted version of aws s3 ls?
We use S3.getObject to fetch it and create a custom response.
Isn't it expensive in terms of egress?
I'm not sure what you're specifically referring to by egress, but data transfer from S3/EC2/ELB etc to CloudFront is free:

> 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.