本文介绍了Cloudfront Origin Group使用Lambda @ Edge检测故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的设置:

我有一个Cloudfront Origin Group,其中Bucket A是主要存储区,而Bucket B是辅助存储区。在 origin-request 上添加Lambda @ Edge来执行特定过程。

I have a Cloudfront Origin Group where Bucket A is a primary bucket and Bucket B is a secondary bucket. Lambda@Edge is added on origin-request to do a certain process.

无论何时向Cloudfront发送请求,我的Lambda @ Edge对其进行了修改以匹配我的存储桶的文件夹结构,并相应地返回文件。

Whenever a request comes to Cloudfront, my Lambda@Edge modifies it to match the folder structure of my bucket and returns file accordingly.

如果存储桶A没有特定文件,则会引发错误,并且Cloudfront故障转移从存储桶B请求该文件。存储桶B与存储桶B的结构不同,它应从存储桶中未经修改的文件路径返回该文件。

If Bucket A doesn't have a certain file it throws an error and Cloudfront failover requests the file from Bucket B. Bucket B doesn't have the same structure as Bucket it, it should return the file from unmodified file path in the bucket.

示例:

我的原始请求: /somefile.html
Lambda @ Edge修改了此请求,以从存储桶A中获取文件: /en/somefile.html

如果存储桶A没有此somefile.html,然后此请求转到存储桶B。它应从最初请求的路径返回文件: /somefile.html 而不是 /en/somefile.html

If Bucket A doesn't have this somefile.html then this request goes to Bucket B. It should return file from the originally requested path: /somefile.html and not /en/somefile.html

以上情况很简单,我的原始场景io非常复杂。基本上,存储桶A的文件路径是经过处理的路径,而存储桶B应该从原始请求的路径返回文件。

The above scenario is very simple, my original scenario is much complex. Basically Bucket A file path is processed path while Bucket B should return file from an originally requested path.

我想要的是

使用Lambda @ Edge如何检测请求是在存储区A还是存储区B上?

Using Lambda@Edge how can I detect if the request is on Bucket A or bucket B?

我该怎么办尝试过:


  • 我尝试在请求标头中添加某些标头,并检查标头是否存在,然后将其请求发送到存储桶B。但这似乎不起作用。

推荐答案

CloudFront的来源主机名将在两个位置之一找到原点请求触发器返回控件后将尝试联系。

The hostname of the origin that CloudFront will try to contact after an origin-request trigger returns control can be found in one of two places.

如果您使用的是CloudFront所说的 S3原点(S3的REST接口)将在此处:

If you are using what CloudFront calls an S3 origin (the REST interface to S3) it will be here:

event.Records[0].cf.request.origin.s3.domainName

如果您使用CloudFront称为自定义来源-我包括S3网站托管端点以及任何其他非S3 REST的原始服务器,位于此处:

If you are using what CloudFront calls a custom origin -- which includes S3 website hosting endpoints as well as any other origin server that isn't S3 REST, it's here:

event.Records[0].cf.request.origin.custom.domainName

这些可以用来确定两个

这篇关于Cloudfront Origin Group使用Lambda @ Edge检测故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 07:37