简体   繁体   English

将 AWS Amplify 前端与 EC2 实例连接?

[英]Connecting an AWS Amplify frontend with a EC2 instance?

So, I'm working on a hackathon project right now, and for the demo, I've spun up a NodeJS Express server on an EC2 via Elastic Beanstalk.所以,我现在正在做一个黑客马拉松项目,为了演示,我通过 Elastic Beanstalk 在 EC2 上启动了一个 NodeJS Express 服务器。 When testing the server's API with our front-end locally, it worked perfectly fine.在本地使用我们的前端测试服务器的 API 时,它运行得非常好。

Now we've deployed our front-end to AWS Amplify, setup a domain name in Route53, and hooked everything up.现在我们已经将我们的前端部署到 AWS Amplify,在 Route53 中设置了一个域名,并连接了所有东西。 When we go to the domain, our front-end looks great, but when we try using the functionality that would connect to our server's API, we get a net::ERR_SSL_PROTOCOL_ERROR .当我们进入域时,我们的前端看起来很棒,但是当我们尝试使用连接到我们服务器 API 的功能时,我们得到一个net::ERR_SSL_PROTOCOL_ERROR

Doing some research, it looks like(?) that we have to setup a certificate on the Classic Load Balancer that's in front of the EC2.做一些研究,看起来(?)我们必须在 EC2 前面的 Classic Load Balancer 上设置一个证书。 So I requested a certificate, and created a listener on the Load Balancer as follows:所以我申请了一个证书,并在负载均衡器上创建了一个监听器,如下所示:

Load Balancer Protocol负载均衡器协议 Load Balancer Port负载均衡器端口 Instance Protocol实例协议 Instance Port实例端口
HTTPS HTTPS 443 443 HTTPS HTTPS 3000 3000

But now I realize that if setup this way, I still have no idea how to point the React Frontend's API calls to the Load Balancer instead of the EC2, or whether the listener is setup correctly.但是现在我意识到如果这样设置,我仍然不知道如何将 React Frontend 的 API 调用指向负载均衡器而不是 EC2,或者监听器是否设置正确。 Would anyone have an idea of what steps we should take here?有没有人知道我们应该在这里采取哪些步骤?

For the details of the app, the backend is a pretty straightforward Express App with CORS enabled, and the frontend is a fairly standard React project, nothing special about either of them.对于应用程序的细节,后端是一个非常简单的 Express 应用程序,启用了 CORS,前端是一个相当标准的 React 项目,两者都没有什么特别之处。

Instance Protocol should be HTTP. Instance Protocol应该是 HTTP。 So your setup uses HTTPS only between client and CLB:因此,您的设置仅在客户端和 CLB 之间使用 HTTPS:

Client--- (HTTPS) ---> CLB --- (HTTP) ---> EC2

Also for properly setup HTTPS, you need to use your own domain.此外,为了正确设置 HTTPS,您需要使用自己的域。 You can't use default domain provided by EB for your application.您不能为您的应用程序使用 EB 提供的默认域。

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

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