Open justcoding121 opened 4 years ago
On a related note, we can extend this idea with multi-region S3 origins, which will help Lambda@Edge use S3 bucket in nearest region. These articles might be helpful: https://aws.amazon.com/blogs/apn/using-amazon-cloudfront-with-multi-region-amazon-s3-origins/, https://www.contentful.com/blog/2019/12/03/making-s3-more-resilient-lambda-edge/. I guess we can use this in addition to origin failover to ensure S3 being down in one region doesn't impact availability.
Also, if we use Lambda@Edge to do this logic instead of configuring S3 origin failover, so we can support more than just primary and secondary. In this way you can create pretty interesting configurations, such as active-active
configuration. I think this is one way to do this:
CloudFront-Viewer-Country
header to origin: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/header-caching.htmlCloudFront-Viewer-Country
and then modify s3 region and domain name to use the closest S3 region to the viewer's country.For static file paths, we should create a minimal origin request handler to minimize cold start perf impact for static file requests.
The benefit is we reduce network latency overall on cache misses for static S3 requests (by distributing it to all S3 regions) though adding some small amount of time (average of 10 ms for similar handler, according to https://aws.amazon.com/blogs/apn/using-amazon-cloudfront-with-multi-region-amazon-s3-origins/)
Is this feature something that would be entertained? If so, I would be willing to assist and test.
Problem When there is an outage in the home bucket region, S3 buckets won't be able to serve cache miss from cloud front.
Solution A solution to this problem is to use origin group failover. https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/high_availability_origin_failover.html
Alternatives I've considered For now, I was able to use origin group for two static file behaviors in cloudfront (_next/static/ and static/ paths). But for lambda@edge behaviors (_next/data/ and Default () paths), I am not sure how this can be done from aws console. I think changes may be needed here to support that using serverless-next.js, for example if lambda@edge is not able to read from primary S3 region, it can look into secondary region. Alternatively, instead of letting lambda@edge work with an S3 origin, let it work with S3 origin group. Any guidance would be appreciated.