简体   繁体   English

AWS:在 S3 静态内容以及 api 网关端点上映射域

[英]AWS: Mapping domain on S3 Static content as well as api gateway endpoints

I am trying to achieve the following domain/path mappings:我正在尝试实现以下域/路径映射:

foo.com -> static web content hosted in AWS S3 foo.com -> 托管在 AWS S3 中的静态 Web 内容

foo.com/dogs -> api gateway endpoint foo.com/dogs -> api 网关端点

foo.com/cats -> api gateway endpoint foo.com/cats -> api 网关端点

foo.com/birds -> api gateway endpoint foo.com/birds -> api 网关端点

What service(s) do I need to use to achieve the above?我需要使用哪些服务来实现上述目标? Thank you.谢谢你。

You have a couple options for this.为此,您有几个选择。 Since you want a single hostname, foo.com, you need to start with a single service that can direct client traffic to s3 and to api gateway.由于您需要一个单一的主机名 foo.com,您需要从一个单一的服务开始,该服务可以将客户端流量定向到 s3 和 api 网关。

Option1: Amazon Cloudfront选项 1:亚马逊 Cloudfront

This one has the benefit of scale.这具有规模优势。

              | -> S3
cloudfront -> |
              | -> api gateway

How to setup cloudfront for API Gateway 如何为 API Gateway 设置 cloudfront

How to seutp cloudfront with S3 如何使用 S3 设置 cloudfront

And since you have cloudfront you might want to see if you can use Lambda@Edge .由于您拥有 cloudfront,您可能想看看是否可以使用Lambda@Edge

Option 2: AWS Amplify选项 2: AWS Amplify

If you don't have a lot of experience with AWS service or even if you do this is a good option I would recommend looking at first as it simplifies a lot of the setup for you and has some nice [features] ( https://aws.amazon.com/amplify/features/ ).如果您对 AWS 服务没有很多经验,或者即使您这样做也是一个不错的选择,我建议您首先查看它,因为它为您简化了很多设置并具有一些不错的 [功能] ( https:/ /aws.amazon.com/amplify/features/ )。 Think of Amplify as service of services for application developers.将 Amplify 视为为应用程序开发人员提供的服务。

Check out (Amplify API)[ https://aws-amplify.github.io/docs/js/api] which is used for creating REST or GraphQL endpoints.查看 (Amplify API)[ https://aws-amplify.github.io/docs/js/api]用于创建 REST 或 GraphQL 端点。

I should mention what frameworks Amplify support: iOS, Android, ReactNative, and for web it has deep integration with React, Ionic, Angular, and Vue.js.我应该提到 Amplify 支持哪些框架:iOS、Android、ReactNative,对于 Web,它与 React、Ionic、Angular 和 Vue.js 深度集成。

And yes, you will probably end up with same solution using Amplify as Option 1 it is which workflow works best for you.是的,您最终可能会使用 Amplify 作为选项 1 获得相同的解决方案,这是最适合您的工作流程。

Option 3 split the service:选项 3 拆分服务:

Create 2 DNS entries for foo.com and api.foo.com为 foo.com 和 api.foo.com 创建 2 个 DNS 条目

          | -> (foo.com) cloundfront -> S3
client -> |
          | -> (api.food.com) api-gateway

You could remove cloudfront in this solution and just use S3 static您可以在此解决方案中删除 cloudfront 并仅使用S3 static

Note on Route53: You do not need to use Route53 as any DNS service will work.关于 Route53 的注意事项:您不需要使用 Route53,因为任何 DNS 服务都可以工作。 If you go with option 1 cloudfront it's just as easy to create the CNAME in any DNS services.如果您使用选项 1 cloudfront,那么在任何 DNS 服务中创建 CNAME 都一样容易。 However, if you are using Amplify then then moving your DNS service to AWS Route53 will automate you DNS management.但是,如果您使用的是 Amplify,那么将您的 DNS 服务移至 AWS Route53 将使您的 DNS 管理自动化。

AWS services required for the above requirements:上述要求所需的 AWS 服务:

  1. Route 53 53号公路
  2. S3 S3
  3. API Gateway API网关

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM