具有多个实例的 AWS ELB 作为 Cloudfront 来源

AWS ELB with multiple instances as Cloudfront origin

我是AWS的新手。我已经知道如何设置 EC2、ELB、S3 和 CF。

现在我有一个疑问,即当具有多个实例(instance0 和 instance1)的 ELB 设置为 Cloudfront 源时,将如何处理 cloudfront 请求。

考虑如下请求到达 Cloudfront edge:

http://distributionId.cloudfront.net/profile_pic_1.png

第一次,请求转到 ELB。 ELB 将请求传递给 instance0 或 instance1。但是 "profile_pic_1.png" 仅存在于 instance1 中。所以在这种情况下是否有可能从 CF 获得 404 错误。

我的 Objective: 我必须创建一个上传服务器。所以一个ELB后面会有很多上传服务器的实例。该 ELB 设置为 CF 的来源。当用户上传照片时,它将临时保存在具有 public 访问权限的实例存储中。上传完成后,我会将上传图片的云端 URL 提供给用户。在这种情况下,用户会从 CF 得到正确的响应吗?

For the first time, request goes to ELB. ELB passes the request to either instance0 or instance1. But "profile_pic_1.png" exist in only instance1. So in this situation is there any possibility to get 404 error from CF.

是的,在这种情况下,CloudFront 有 50% 的机会获得 404 响应而不是图像,并且 CloudFront 会简单地将错误响应传递给客户端。您永远不想将具有不同内容的实例放在负载均衡器后面。

您的设计中缺少的是 Amazon 的 S3 服务。您应该将所有图像上传到 S3 而不是 EC2 服务器。并且您应该配置 CloudFront 以直接从 S3 中提取图像。