I am trying to deploy Google Cloud Function from local system using the gcloud command-line tool.
My files are compressed in a .zip file. As described in the attached screenshot the zip file contains main.py and requirement.txt
main.py (took from web for testing)
from wand.image import Image
from google.cloud import storage
client = storage.Client.from_service_account_json(
'C:\\Users\\an20086686\\AppData\\Local\\Google\\Cloud SDK\\deploy\\****-*****-poc-e4b410a65986.JSON')
THUMBNAIL_BUCKET = 'a_demo_storage_trigger1'
def make_thumbnail(data, context):
bucket = client.get_bucket(data['****_my-awesome-bucket'])
blob = bucket.get_blob(data['name'])
imagedata = blob.download_as_string()
newimage = Image(blob=imagedata)
newimage.sample(200,200)
bucket = client.get_bucket(THUMBNAIL_BUCKET)
newblob = bucket.blob('thumbnail-' + data['name'])
newblob.upload_from_string(newimage.make_blob())
requirements.txt
google-cloud-storage
Wand
Using the command below to deploy this function:
gcloud beta functions deploy make_thumbnail --runtime python37 \
--trigger-bucket ****_my-awesome-bucket \
--trigger-event google.storage.object.finalize
Error 1 : (gcloud.beta.functions.deploy) unrecognized arguments: google.storage.object.finalize
When I use:
gcloud beta functions deploy make_thumbnail --runtime python37 \
--trigger-bucket ****_my-awesome-bucket \
--trigger-event google.storage.object.finalize
ERROR: (gcloud.beta.functions.deploy) OperationError: code=3,message=Function failed on loading user code.
Error message: File main.py that is expected to define function doesn't exist
Log of the encountered error: