lambda@edge vs lambda的性能和成本比较作为云沿起源
我正在创建一个服务,其中客户需要将一些数据存储在DynamoDB表中。我将CloudFront用作减少延迟的CDN。我有2种从DynamoDB表获得数据的方法。
方法1: 客户端向CloudFront发送请求。 CloudFront检查缓存的响应。假设没有缓存的响应,云方面带有原始请求触发器调用lambda@edge函数。 lambda@edge函数查询DynamoDB表,获取数据并将其发送到CloudFront Edge位置。 CloudFront缓存了lambda@edge功能的响应,并响应客户端。问题:在这种情况下,应该设置什么云偏发?
方法2: 客户将请求发送到CloudFront。云前检查缓存的响应。假设没有缓存的响应,则CloudFront将请求转发到Origin,在这种情况下,这将是lambda函数。 Lambda接收CloudFront请求并查询DynamoDB表,获取数据并将其发送回CloudFront Distribution。 CloudFront Edge服务器缓存响应,并将其转发给客户端。
在延迟和成本方面,哪种方法会更好。还有一种更好的方法来解决这个问题吗?
I'm creating a service where a client needs to get some data stored in a DynamoDB table. I'm using Cloudfront as a CDN for reducing latency. I have 2 methods of obtaining the data from the DynamoDB table.
Method 1:
The client sends a request to Cloudfront. Cloudfront checks for a cached response. Assuming a cached response is not available, Cloudfront invokes a Lambda@Edge function with an Origin Request trigger. The Lambda@Edge function queries the DynamoDB table, gets the data and sends it to the Cloudfront edge location. Cloudfront caches the response from the Lambda@Edge function and responds to the client. Question: what should the Cloudfront origin be set in this case?
Method 2:
Client sends a request to Cloudfront. Cloudfront checks for cached response. Assuming a cached response is not available, Cloudfront forwards the request to the origin, which in this case will be a Lambda function. The Lambda receives the Cloudfront request and queries the DynamoDB table, gets the data and sends it back to the Cloudfront distribution. Cloudfront edge server caches the response, and forwards it to the client.
Which method would be better in terms of latency, and in terms of cost. Also is there a better way to solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
方法1-只需将S3存储桶设置为原点,(您需要设置一些东西),
并确保您每次都从Origin请求Edge Lambda返回(并且永远不会达到S3),
我认为价格或性能之间没有显着差异!我认为,您的大部分电话都会被缓存。从长远来看,如果您具有良好的缓存命中率,我会说几乎相同!
Method 1 - just set a S3 bucket as an origin, (you need to set something),
and make sure you return from the origin request edge lambda every time (and it would never reach the S3)
I don't think there is a significant difference between pricing or performance! Most of your call would be cached I assume. In the long term I would say it would be almost the same, if you have a good cache hit ratio!