Daniel
Daniel

Reputation: 5391

Cloud Run Fails to Import Custom Package from Artifact Registry (Terraform Deployment)

I'm deploying a Cloud Run function using Terraform, and the function depends on a custom Python package that we uploaded to Google Artifact Registry using Twine. However, the deployment fails with the following error:ModuleNotFoundError: No module named 'google.cloud.logging'

Traceback (most recent call last):
  File "/layers/google.python.pip/pip/bin/functions-framework", line 8, in <module>
    sys.exit(_cli())
  File "/layers/google.python.pip/pip/lib/python3.9/site-packages/click/core.py", line 1161, in __call__
    return self.main(*args, **kwargs)
  ...
  File "/workspace/main.py", line 1, in <module>
    from ddsgcloud.utils import cloud_helpers as ch
  File "/layers/google.python.pip/pip/lib/python3.9/site-packages/ddsgcloud/utils/cloud_helpers.py", line 1, in <module>
    import google.cloud.logging
ModuleNotFoundError: No module named 'google.cloud.logging'

Setup: The function runs Python 3.9 and is deployed using Terraform. The custom package is stored in Artifact Registry (ddsgbq is the repository, not the package name).

I uploaded the package using twine:

twine upload --repository-url https://us-central1-python.pkg.dev/dev-di-dashboards-data/ddsgbq/ dist/*

requirements.txt contains:

###### core dependencies
click 
google-api-core
google-auth
google-cloud-appengine-logging
google-cloud-audit-log
google-cloud-bigquery
google-cloud-bigquery-storage
google-cloud-logging
google-cloud-core
pandas
pandas-gbq
ipython
jupyter
jupyterlab
jupyterlab-git
pyarrow
numpy
twine
keyrings.google-artifactregistry-auth
tabulate
google
itables
protobuf 
google-cloud-logging
google-cloud-pubsub
jira
python-dateutil

Terraform deployment:

resource "google_cloudfunctions2_function" "cloud_function_v2" {
  name        = "dds-inovapp"
  description = "Function for inovapp operations"
  runtime     = "python39"
  service_config {
    service_account_email = "[email protected]"
  }
}

What I Suspect:

What I’ve Tried:

Questions:

Upvotes: 0

Views: 41

Answers (0)

Related Questions