静态页面的 CloudFront 身份验证

CloudFront authentication for static page

我有一个基于 Tomcat 的简单 Java 网络应用程序,使用标准 servlet 为静态文件提供服务。我想使用 CloudFront 来减少 web 应用程序的负载并提高静态文件传输的速度。我需要我的静态文件只提供给那些具有有效身份验证 cookie 的请求。检查 cookie 的有效性必须在代码中完成。我对 CloudFront 的经验不多,但我认为它类似于服务器端缓存。现在我怎样才能让这个缓存只对经过身份验证的请求起作用? 我知道一种选择是在我的 webapp 中进行身份验证,然后重定向到某个临时 URL 到 CF。但我担心它可能会很慢。可能有更好的解决方案吗?

身份验证要求背后的原因之一是您需要为通过 CF 传送的数据量付费。如果有人能够不受控制地从我的 CF 中获取数据,我最终可能会付出很多钱。

感谢您的任何提示,我在 SO 和 AWS 方面都是新手。我试图 google 找到答案已经有一段时间了,我也在 SO 中进行了搜索,但一无所获。

您可以向您的用户提供已签名的 URL。检查一下:https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/PrivateContent.html

When you create signed URLs or signed cookies to control access to your objects, you can specify the following restrictions:

  • An ending date and time, after which the URL is no longer valid.

  • (Optional) The date and time that the URL becomes valid.

  • (Optional) The IP address or range of addresses of the computers that can be used to access your content.

One part of a signed URL or a signed cookie is hashed and signed using the private key from a public/private key pair. When someone uses a signed URL or signed cookie to access an object, CloudFront compares the signed and unsigned portions of the URL or cookie. If they don't match, CloudFront doesn't serve the object.