Diagnosing the error in a Postgresql to Redshift migration through psycopg2
This is because you are querying a postgresql replica that doesn't allow queries to run for very long.  Your only solution is to ask the database administrator to increase the query limit on that replica, or hit production instead.