Erwin
Erwin

Reputation: 87

GCP functions deployment function failed

A python function is created in GCP function to modify the metadata of objects in storage. An error is displayed during deployment,The error message is as follows:

Function failed on loading user code. This is likely due to a bug in the user code. 
Error message: Error: please examine your function logs to see the error cause: 
https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs. Additional 
troubleshooting documentation can be found at 
https://cloud.google.com/functions/docs/troubleshooting#logging. Please visit 
https://cloud.google.com/functions/docs/troubleshooting for in-depth troubleshooting 
documentation.

My function code is as follows:

from google.cloud import storage

def set_blob_metadata(bucket_name, blob_name):
    """Set a blob's metadata."""
    # bucket_name = 'your-bucket-name'
    # blob_name = 'your-object-name'

    storage_client = storage.Client()
    bucket = storage_client.bucket(lrving)
    blob = bucket.get_blob(index.html)
    metadata = {'Cache-Control': 'no-store'}
    blob.metadata = metadata
    blob.patch()

    print("The metadata for the blob {} is {}".format(blob.name, blob.metadata))

How to solve this problem? thank you!

Upvotes: 0

Views: 353

Answers (2)

Mabel A.
Mabel A.

Reputation: 2015

Based on the error message you mentioned, the issue is caused by your runtime not having a Cloud Storage module in it. In addition to Guillaume's answer, you need to install that dependency during function deployment. You can do so by adding google-cloud-storage to your requirements.txt file.

For example:

google-cloud-storage==1.41.0

More information can be found here on how to specify Python dependencies for Cloud Functions.

Upvotes: 2

guillaume blaquiere
guillaume blaquiere

Reputation: 75715

Your function signature is wrong. You need to comply with the platform definition

You will have the data that you need in the function parameters.

Upvotes: 0

Related Questions