动态选择由CloudFront服务的S3对象 [英] Dynamically choose an S3 object to be served by CloudFront

查看:77
本文介绍了动态选择由CloudFront服务的S3对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以让自定义源服务器告诉CloudFront直接从S3存储桶中提供文件,类似于X-Sendfile在Nginx中的工作方式?我想避免不得不从S3中读取文件并将其通过管道传输到CloudFront。

Is it possible to have a custom origin server tell CloudFront to directly serve a file from an S3 bucket, similar to the way X-Sendfile works in Nginx? I'd like to avoid having to read the file from S3 and pipe it to CloudFront.

推荐答案

不,这不是

将请求从CloudFront发送到原始服务器后,CloudFront会做 only (当然,除非发生错误) )将原始服务器的响应返回给请求者。

Once the request is sent from CloudFront to the origin server, the only thing CloudFront will do (unless an error occurs, of course) is return the origin server's response to the requester.

唯一可以想到的唯一可能的方法是CloudFront遵循HTTP重定向,而< a href = http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/RequestAndResponseBehaviorCustomOrigin.html#ResponseCustomRedirects rel = nofollow>它不会这样做。

The only way that comes to mind in which this could really be possible would be if CloudFront followed HTTP redirects, which it does not do.

如果您希望在请求到达原始位置后从其他地方返回内容,则必须将其获取并流回去……如果存储桶与原始服务器位于同一区域,并且您的代码很紧凑。区域内到S3的等待时间非常短,可用带宽很高。我有一个应用程序可以在一个t2实例上每天执行数千次这样的操作,因此它确实可行。

If you want to return content from elsewhere once the request has arrived at the origin, you'll have to fetch it and stream it back... which will probably perform better than you expect, if the bucket is in the same region as the origin server and your code is tight. The latency to S3 within a region is very low and the available bandwidth is high. I have an application that does exactly this, many thousands of times each day on a little t2 instance, so it's certainly viable.

当然,只有一个CloudFront分配,您可以有多个来源-例如您的服务器和S3。 CloudFront可以根据路径模式匹配来选择哪个来源将处理每个请求...但这是静态映射,因此我不知道它是否适用于您要执行的操作。

Of course, with a single CloudFront distrubution, you can have multiple origins -- such as your server and S3. CloudFront can choose which origin will handle each request based on path pattern matching... but that's a static mapping, so I don't know whether it applies to what you're trying to do.

这篇关于动态选择由CloudFront服务的S3对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆