CloudFront 和 API 网关缺少身份验证令牌错误

Missing Authentication Token Error with CloudFront & API Gateway

我已经设置了一个 CloudFront 分配,其中一个 API 网关作为源之一,这个 API 网关配置了一个 AWS IAM 授权方。

当使用授权 headers 调用 CloudFront url 时,它 returns 出现 403 错误。

{
    "message": "Missing Authentication Token"
} 

但是,当调用 API 网关 url 而不是具有相同授权 headers 的 CloudFront url 时,它起作用了。

我还尝试通过 CloudFront url 在没有任何授权者的情况下调用端点并且它有效。关于如何解决这个问题的任何想法。

配置 CloudFront 分配时,请记住 CloudFront removes most headers from the request by default

这样做是为了优化缓存命中率,同时防止您的原始服务器根据那些 headers 做出决定,这些 headers 不适合基于那些[的其他变体(或不存在)的不同请求=28=]s,然后 CloudFront 将不恰当地从缓存中提供服务。

您需要 whitelist Authorization header 才能转发到源。

另请注意,在您控制的 CloudFront 分配后面配置 API 网关时,您可能希望将 API 端点部署为 地区性 而不是 edge-optimized.