Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Connection time out issue while accessing external api() from gcp cloud function

The problem statement deals with following scenario. I am trying to run a cloud run function from gcp platform that eventually accesses an external api. The cloud run function has a python code that accesses this external REST api (). The purpose of the function is to help fetching the response data (if request and response worked fine) & getting this "content" in a .csv file thus to finally move to a cloud storage that is created. However, the issue encountered here is, the cloud run function is ended up with throwing following error, for example 

requests.exceptions.ConnectionError: HTTPConnectionPool(host='10.109.21.177', port=8097): Max retries exceeded with url: /auth/realms/ocs-tenant-1/protocol/openid-connect/token (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x3e04029addf0>: Failed to establish a new connection: [Errno 110] Connection timed out'))

As the message indicates, the time out error may be originated from a network issue (though very generic indeed) which could have several reasons. When same REST api () was accessed from local virtual machines, it worked fine and the required response (200) and response body both were obtained

Few other details

  • The Rest api url, "http://10.109.21.177:8097/auth/realms/ocs-tenant-1/protocol/openid-connect/token
    • The required headers, data along with this url was passed to get the response.
  • The required packages for the python script were all listed under requirements.txt
  • The required bucket that was aimed to hold the csv file (after api request gets success and was able to fetch the response data) was created over cloud storage earlier. 

From general configurations perspective (of having maximized time out settings | or having secured permissions etc.) all aspects were ensured. However, from network setting perspective, is there any measure to be taken care in lieu with VPC connector and/or NAT gateway to help resolving this? Any pointer and /or links on this is highly appreciated. 

2 1 935
1 REPLY 1