Google Cloud Function HTTP request connection times out

Dylan Solms

I am performing an http request to the LibreNMS API via the following Python code:

import requests
TOKEN = './token.json'
def get_request(request_type):
    url = f'http://192.168.1.141/api/v0/{request_type}'
    with open(TOKEN,'r') as file:
        headers = json.load(file)
    response = requests.get(url,headers=headers)
    if response.status_code == 200:
        pass
    else:
        print(f"Failed to pull for {request_type}: {response.status_code}")
    return response.json()
if __name__ == '__main__':
    dat = get_request('alerts') # pull alerts

The script runs perfectly on my local machine and quite fast. However when I try to deploy the scrip as a Google Cloud Function then requests.get(url,headers=headers) seems to time out. In the cloud logs of the function I get:

Traceback (most recent call last):
  File "/layers/google.python.pip/pip/lib/python3.11/site-packages/urllib3/connection.py", line 203, in _new_conn
    sock = connection.create_connection( 
"Traceback (most recent call last):
  File "/layers/google.python.pip/pip/lib/python3.11/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request("
 "Traceback (most recent call last):
  File "/layers/google.python.pip/pip/lib/python3.11/site-packages/requests/adapters.py", line 489, in send
    resp = conn.urlopen("
Traceback (most recent call last):
  File "/layers/google.python.pip/pip/lib/python3.11/site-packages/flask/app.py", line 2529, in wsgi_app
    response = self.full_dispatch_request()"

I have the same versions of requests==2.28.1 and urllib3==1.26.14 installed on my local machine and in the requirements.txt file of the cloud function. I thought the problem might lie here.

I am unsure if a cloud function can perform http requests to non-Google services. Perhaps this is the issue.

Please help me understand what is wrong with my function and/or deployment.

Update

It seems that the issue lies within the fact that the address 192.168.1.141 was local. I have since replaced it with librenms.bctechnologies.co.za:8050. However, it seems like this too is not public as response = requests.get(url,headers=headers) keeps timing out.

Yvan G.

Posting @Guy comment as answer wherein running LibreNMS as a better option to access privately. The purpose of this post is to guide other users for this concern.

Just to add, if by chance you wanted to continue to access your Cloud Function using GCP Cloud VPN you can do this by creating first a connector which is Serverless VPC access.

After the connector, the next step is by associating your Cloud Function to the connector that is created. You can do this by editing the Cloud Function and follow this steps in Configure Cloud Functions to use a connector.

Once Cloud Function is using the connector, the next step is to create a Cloud VPN. Just make sure that you will choose the network you use in your Serverless VPC access to have a connection to your Cloud Function.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Cloud Functions times out when calling an external HTTP with a POST request

google cloud function times out, apparently during database access

HTTP function times out when subscribing an FCM token to a topic in Cloud Function

Multiple returns on HTTP request in Firebase / Google Cloud Function

Google Cloud HTTP function by webhook: Request body is missing data

Mock a HTTP request that times out with HTTPretty

Google Cloud Build of Angularfire project times out

node-http-proxy POST request times out

iOS: HTTP POST request times out when setting httpBody property

OPA HTTP self referential PUT request times out

HTTP request is not the same on Heroku and Google Cloud Run

Verify HTTP request from Google Cloud Scheduler

Python Google Cloud Function Connection reset by peer

Close redis connection on google cloud function end

Google Cloud Function finished with status: 'connection error'

http request from website to cloud function in php

http post request firebase cloud function

Firebase cloud function http request to another firebase cloud function

Image Moderation always times out on Google Firebase cloud functions?

Puppeteer PDF Creation on Firebase Functions (Google Cloud) times out

Google Cloud Build via cloudbuild.yaml times out randomly

Cloud Function writing to Firebase Realtime Database times out

SOAP Request with HTTP Client with client certification connection timed out Exception

Connection time out after request is read: http-incoming-3931

Google Cloud Function - SendGrid - 400 Bad Request

google cloud function is not able to capture the post request

Python Google cloud function and JavaScript Post request

Bad request returned from google cloud function

Connection timed out: Nodejs Google App Engine to Cloud MySql