AWS - Unable to make API calls to EC2 server via Application Load Balancer (ALB)

生来就可爱ヽ(ⅴ<●) 提交于 2020-08-10 19:14:30

问题


I am trying to deploy a MERN Stack app to AWS but I am kinda stuck now.

Current Progress:

  1. ALB is set up with a valid SSL Certificate issued by AWS.

    ALB URL: https://xyz.alb.com/

    Also, ALB has three listeners:

     a. HTTP [80]
     b. HTTPS [443]
     c. HTTPS [5000] (For accessing ec2 backend server, is this right?)
    
  2. EC2 instance public IP: 78.45.43.23 (Say)

    (I can access my server on 78.45.43.23:5000/api/)

  3. I have whitelisted, ALB, https://xyz.alb.com in my server CORS (Node) [Important].

Problem Statement:

When making an API call now to https://xyz.alb.com:5000/api/getUser, ideally, it should redirect to 78.45.43.23:5000/api/getUser and get me the response since I have the target instance setup [healthy ec2 instance].

But instead, I get,

Access to fetch at 'https://xyz.alb.com:5000/api/getUser' from origin 'https://xyz.alb.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

In short, I am not sure if I am being able to hit my server at PORT 5000 or not, by using the ALB URL!

I would be more than happy to provide any code/screenshot further needed to support my question.

Thanks in advance!

来源:https://stackoverflow.com/questions/63317832/aws-unable-to-make-api-calls-to-ec2-server-via-application-load-balancer-alb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!