i'm trying to deploy my simple apollo-server on an Ubuntu 18.04 instance from Amazon Web Services(AWS) EC2. It works fine, but i need/want the traffic to be over HTTPS instead. I was wondering which could be the best option. Im running the code with "forever"("forever start lib/index.js"), also using yarn (to start the project "yarn start"). I'm able to access the server with the ip address () and everything works fine. I would like to do it ASAP, already tried with apollo-server-lambda and others Nodejs hosting websites.
1 Answer
The easier way to do this on AWS is by using a EC2 load balancer. You just need to create an application load balancer and add your instance to the target group. Once you have the load balancer created, you can apply the SSL certificate easily on your load balancer. This approach doesn't require you to change your application code at all.
Please refer this docs. https://docs.aws.amazon.com/elasticloadbalancing/latest/application/create-application-load-balancer.html
If you don't want to use a load balancer, you need to apply the SSL certificate on the application level. Hope this helps.
-
I was really hoping for this one, i m able to get the load balancer up, but with "502 bad gateway" error, either by http & https. Nov 26, 2019 at 9:04
-
I think thats because the load balancer uses the healh check to identify the healthy instances. Did you configure the health check. Does it show one healthy instance. Nov 26, 2019 at 9:08
-
Well, exactly as you said, my instance listening on port 4000 (apollo server) is unhealthy "health checks failed with these codes:[502]" Nov 26, 2019 at 9:12
-
Okay, if im setting up the health check on "Edit health check" the protocol should be http and the path must be "/"? Or "/lib/index.js? Because im using Yarn to run the project Nov 26, 2019 at 9:16
-
The protocol should be http, because traffic to load balancer is https. But traffic to instance from the load balancer is http. The url should be a route exposed by your application. For e.g if you are using express, it could be one of the routes you have defined in express that will return 2xx http response. Alternatively you can set the protocol to TCP and set the port to 4000 Nov 26, 2019 at 9:46