在请求的标头中获取 CloudFront 自定义域

Kri*_*ian 5 amazon-cloudfront aws-lambda aws-api-gateway

我有一个 CloudFront 分配,abcd1234.cloudfront.net并且我已经向分配中添加了一个自定义域mysite.com

  • CloudFront 分配的来源: aaabbbccc.execute-api.us-east-1.amazonaws.com
  • 当我加载页面时mysite.com/hello/world,CloudFront 正在使用 API Gatewayaaabbbccc.execute-api.us-east-1.amazonaws.com/prod/{proxy+}
  • the API Gateway path endpoint is invoking a Lambda Function that calls a function like getPageContent(customDomainName, pagePath) which should be mysite.com and /hello/world respectively.
  • However, inside that function, the Host header that eventually makes it into the function's event.headers.Host value is never the custom domain. Instead, the Host header is always aaabbbccc.execute-api.us-east-1.amazonaws.com.

I want headers.Host to equal mysite.com (or another header to show that the request comes from mysite.com, but no matter what I do, the Host value is always just the origin url.

Edit: I tried whitelisting Host and it caused the site to break completely, with the error about not being able to reach the CloudFront distribution.