如何从不同区域的多个存储桶支持的 S3 提供静态 Web 内容

问题描述 投票:0回答:3

我正在尝试从 S3 存储桶提供静态 Web 内容(HTML、CSS 和 JS 文件)。我知道我可以转到存储桶的属性选项卡,然后从

Use this bucket to host a website
框中选择项目
Static website hosting
。我确信这一步仍然是我正在寻找的解决方案的一部分,但它不会是全部。

这就是我想要实现的目标:

将相同的内容部署到多个区域,并根据可用性和/或延迟向客户端提供服务。

至于API网关,我知道怎么做。我应该在所有区域创建相同的 API 网关(以及底层 lambda 函数)和自定义域名。然后在 Route 53(CNAME 类型)上创建相同的域,并选择延迟作为路由策略。人们还可以为记录集设置运行状况检查,以便定期检查 API 网关和 lambda 函数的可用性。

现在我想对 S3 存储桶和我的静态内容执行相同的操作。即,我想将相同的内容部署到不同的区域,并以某种方式使 Route 53 将请求路由到“最近的可用”存储桶。以前,我使用的是 CloudFront,但在我看来,在这种设置中,我只能引入一个存储桶。 有谁知道如何从多个存储桶中提供静态内容?如果您打算建议 CouldFront,请告诉我您打算如何使用多个存储桶。

amazon-web-services amazon-s3 amazon-cloudfront
3个回答
3
投票
证书

,设置CloudFront发行版以从您的存储桶中获取内容,然后使用Route53将您的域指向您的发行版。您可以获得免费的 https,还可以添加多个 S3 存储桶作为您的发行版的来源。

来自 AWS 文档:

After you configure CloudFront to deliver your content, here's what happens when users request your objects: 1. A user accesses your website or application and requests one or more objects, such as an image file and an HTML file. 2. DNS routes the request to the CloudFront edge location that can best serve the request—typically the nearest CloudFront edge location in terms of latency—and routes the request to that edge location. 3. In the edge location, CloudFront checks its cache for the requested files. If the files are in the cache, CloudFront returns them to the user. If the files are not in the cache, it does the following: 3a. CloudFront compares the request with the specifications in your distribution and forwards the request for the files to the applicable origin server for the corresponding file type—for example, to your Amazon S3 bucket for image files and to your HTTP server for the HTML files. 3b. The origin servers send the files back to the CloudFront edge location. 3c. As soon as the first byte arrives from the origin, CloudFront begins to forward the files to the user. CloudFront also adds the files to the cache in the edge location for the next time someone requests those files.

P.D.请记住,这仅适用于静态内容!


0
投票

请参阅此博客以获取示例 Lambda@Edge 代码来执行此操作 -

https://aws.amazon.com/blogs/apn/using-amazon-cloudfront-with-multi-region-amazon-s3-origins/


0
投票

SWS控制台快速云架构构建服务。

您可以通过简单的输入轻松控制AWS资源。请参阅以下文档:

如何使用SWS控制台轻松部署到AWS S3 + CloudFront架构

如何创建证书并使用SWS控制台连接Route53域

您可以随意使用SWS Console轻松部署到AWS S3 + CloudFront架构并创建证书和连接Route53域!

进入Sws控制台服务页面

© www.soinside.com 2019 - 2024. All rights reserved.