HTTP 504 error when trying to call APIs from Node.js

Hello everyone.
I’m having problems when trying to call the route of my HTTP GET request API. The same program works when I try to make the same communication with a VM which hosts Kong API Gateway. Then I tried to host it on AWS EC2 instance but I figured out this problem.

I opened the ports 8000 and 8001 creating inbound rules in the security group and I tried to modify the kong.conf file as well to allow communication from anyone, but I can’t solve.

Can anyone help me please? Thanks in advance

@dbadini - Where is your kong and Node JS running ? which backend are you trying to connect ?

504 error is issue with your upstream.

Thanks for replying! Locally on my Windows host, I have two Node.js programs: server.js and db_addon.js (ideally db_addon.js has to be on another machine, it is the next step). Server.js makes calls to the Kong api gateway which is running on an AWS ec2 instance to solve the API to call db_addon’s services. But I got 504 HTTP error.
Before I tried the same communication between my windows host and a Ubuntu VM and it was working fine. Could it be mandatory an HTTPS communication?

Just to clarify my understanding to answer you better, can you confirm the ones marked ?

Server JS (local) → Kong (EC2) → DB Service (local ? )

One that works, Server JS (local) → Kong (Ubuntu- Local in same host ? ) → DB Service (local)

This is the wanted flow: Server JS (local) → Kong (EC2 instance 2) → DB Service (EC2 instance 1)

The one that works: Server JS (local) → Kong (VM Ubuntu in local) → DB Service (EC2 instance 1)

In the working communication flow, Kong refers services of db_addon JS (local at the moment) accessed by Server JS.

I hope now it is more clear.

For the failing ones what’s the flow ?

Also check the logs here as given in your kong.conf, you can find if its failing at Gateway or upstream.

proxy_access_log = logs/access.log

The failing flow is this one: Server JS (local) → Kong (EC2 instance 2) → DB Service (EC2 instance 1)

This is a typical log from the access.log, but it doesn’t give me more informations:
[06/Dec/2023:11:01:24 +0000] “GET /getall HTTP/1.1” 504 102 “-” “axios/1.6.2” kong_request_id: “65d5b75bf5dfb946ec9a855e797e414c”

Could it be that Kong blocks the communication because over the internet it must be mandatory via HTTPS protocol? I was thinking this but I can’t find anything about it in the documentation

HTTPS is not a mandatory but a good practice. For testing purpose it should not matter.

Check the following,

  1. If in your security group whether the port connection is allowed to your DB service from Kong instance. Inbound rule on DB service should have the entry.
  2. Login to Kong instance via SSH and try curl to your DB service (curl -v http://IP/getall)
  3. If you are using external IP for DB service in Kong upstream, try the internal IP of instance

Sorry for the misunderstanding. Now I understand what you were asking me. You certainly meant the one used by Kong as DB Service. Well that resides on the same machine where Kong is running (basic installation via script). By DB Service I meant the MySQL instance to which the db_addon service refers, which resides on a different EC2 instance (but this is not what interests us).

I am certain its an issue with your upstream service.

  1. To test the theory of no issues in Kong, individually test your DB service directly without proxying via Kong, to see if its responding with success.

  2. Optionally, can you try creating a service and a route to test it.

Possibly share the response in both cases. This will narrow down your issue.