1

I am using python and the serverless framework to deploy functions to AWS Lambda. I have been running into an issue when I want to run a SQL query and then output the results into a google sheet. My code functions perfectly locally, but not on AWS lambda.

I am also using a VPC configuration, however, I have already verified it has internet access and everything else in my code functions properly in Lambda.

    gc = pygsheets.authorize(service_account_env_var=service_account)
    ws = gc.open(workbook_name)
    wks = ws.worksheet_by_title(sheet_name)
    wks.set_dataframe(df, (row_num, col_num))

The code breaks when calling ws = gc.open(workbook_name) and returns the error.

gc = pygsheets.authorize(service_account_env_var=service_account) This code works when creating my pygsheets client.

Bellow is the error message returned:

[ERROR] OSError: [Errno 97] Address family not supported by protocol
Traceback (most recent call last):
  File "/var/task/handler.py", line 70, in main
    pd_to_gsheets(workbook_name=workbook, sheet_name=test_sheet, df=df, row_num=1, col_num=1)
  File "/var/task/handler.py", line 31, in pd_to_gsheets
    ws = gc.open(workbook_name)
  File "/var/task/pygsheets/client.py", line 143, in open
    spreadsheet = list(filter(lambda x: x['name'] == title, self.drive.spreadsheet_metadata()))[0]
  File "/var/task/pygsheets/drive.py", line 144, in spreadsheet_metadata
    return self._metadata_for_mime_type(self._spreadsheet_mime_type, query, only_team_drive)
  File "/var/task/pygsheets/drive.py", line 169, in _metadata_for_mime_type
    return self.list(fields=FIELDS_TO_INCLUDE,
  File "/var/task/pygsheets/drive.py", line 87, in list
    response = self._execute_request(self.service.files().list(**kwargs))
  File "/var/task/pygsheets/drive.py", line 427, in _execute_request
    return request.execute(num_retries=self.retries)
  File "/var/task/googleapiclient/_helpers.py", line 134, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/var/task/googleapiclient/http.py", line 905, in execute
    resp, content = _retry_request(
  File "/var/task/googleapiclient/http.py", line 176, in _retry_request
    resp, content = http.request(uri, method, *args, **kwargs)
  File "/var/task/google_auth_httplib2.py", line 209, in request
    self.credentials.before_request(self._request, method, uri, request_headers)
  File "/var/task/google/auth/credentials.py", line 133, in before_request
    self.refresh(request)
  File "/var/task/google/oauth2/service_account.py", line 376, in refresh
    access_token, expiry, _ = _client.jwt_grant(
  File "/var/task/google/oauth2/_client.py", line 153, in jwt_grant
    response_data = _token_endpoint_request(request, token_uri, body)
  File "/var/task/google/oauth2/_client.py", line 105, in _token_endpoint_request
    response = request(method="POST", url=token_uri, headers=headers, body=body)
  File "/var/task/google_auth_httplib2.py", line 119, in __call__
    response, data = self.http.request(
  File "/var/task/httplib2/__init__.py", line 1708, in request
    (response, content) = self._request(
  File "/var/task/httplib2/__init__.py", line 1424, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/var/task/httplib2/__init__.py", line 1346, in _conn_request
    conn.connect()
  File "/var/task/httplib2/__init__.py", line 1182, in connect
    raise socket_err
  File "/var/task/httplib2/__init__.py", line 1132, in connect
    sock = socket.socket(family, socktype, proto)
  File "/var/lang/lib/python3.8/socket.py", line 231, in __init__
    _socket.socket.__init__(self, family, type, proto, fileno)
gbachRM
  • 11
  • 1

0 Answers0