Getting 504 timeout errors

We have grafana 6.4 installed on 3 of our ec2 instances and configured them such that they use mysql RDS instance as a database. (Basically we are trying to setup high available grafana cluster).

Now, we configured an application loadbalancer in front of these three grafana servers. But we are receiving 504 gateway timeout errors. Can any one help me with this?