最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How can I ensure my AWS Lambda function uses the CloudFront domain instead of the API Gateway URL for the canonical link in my Q

programmeradmin0浏览0评论

I have an AWS Lambda function connected to an API Gateway (Regional HTTP API) and my domain is linked to CloudFront. However, my application's canonical URL is being set to the API Gateway domain instead of my CloudFront domain. How can I ensure that my Lambda function correctly uses the CloudFront domain in the canonical URL when for example react or qwik js generates SSR?

I have an AWS Lambda function connected to an API Gateway (Regional HTTP API) and my domain is linked to CloudFront. However, my application's canonical URL is being set to the API Gateway domain instead of my CloudFront domain. How can I ensure that my Lambda function correctly uses the CloudFront domain in the canonical URL when for example react or qwik js generates SSR?

Share Improve this question asked 9 hours ago Aren SadeAren Sade 5661 gold badge9 silver badges26 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

To ensure your Lambda function receives the correct domain (CloudFront instead of API Gateway), you need to configure CloudFront to forward the Host header. By default, CloudFront may replace the Host header with the API Gateway domain, which can result in an incorrect canonical URL.

Unfortunately, as far as I know, there is no direct way to pass the user's Host value from CloudFront to API Gateway and then to the Lambda function. However, a workaround I found is to create a whitelist header in CloudFront that exlude the Host value. Then, in API Gateway, you can use "parameter mapping" to set a static domain address (without the http(s) protocol, e.g., example).

While this may not be an ideal solution, it at least helps maintain consistency across different deployments, such as staging and production.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论