To fix the issue you can do I have experienced the same issue, but in a slightly different context. I was deploying Node.js/Express application using the AWS Elastic Beanstalk and was able to install an SSL certificate on it. The result of this was that my application was accessible on both the http and https protocol. The routing table of the load balancer were looking like this :
Hope this helps In my case, it turns out that there was no problem with the load balancer. The final solution ending up being Ubuntu's hosts file in which there was an inexplicable entry to route traffic from some mystery IP to my application's host name. So, during the process of creating the PDF, paths were getting re-written by the PDF generator to point at the mystery server, and hence the Gateway timeout issues. I have no idea why it was occasionally working and not failing.
around this issue After some attempts, I solved the issue setting the idle timeout attribute of the load balancer, as explained here in theory, because nothing was wrong with the single ECS Tasks. In Cloudformation, it was enough to add the attribute setting of the parameter, and double the default value.