I'm trying to create a cloud function using api, the source code will be provided in a zip archive which includes an index.js & package.json files. I have uploaded this archive to storage bucket and create a cloud function via API request but now I need to extract this zip archive to point out the source for cloud function, how can I achieve that?
Here's what I have done: From views.py
sclient = storage.Client()
bucket = sclient.get_bucket(func_obj.bucket)
blob = bucket.blob(func_obj.sourceFile.name)
print('Uploading archive...')
print(blob.upload_from_filename(file_name))
name = "projects/{}/locations/us-central1/functions/{}".format(func_obj.project, func_obj.fname,)
print(name)
req_body = {
"name": name,
"entryPoint": func_obj.entryPoint,
"timeout": "3.5s",
"availableMemoryMb": func_obj.fmemory,
# "sourceUploadUrl": upload_url,
"sourceArchiveUrl": "gs://newer_bucket/func.zip",
"httpsTrigger": {},
}
service = discovery.build('cloudfunctions', 'v1')
func_api = service.projects().locations().functions()
response = func_api.create(location='projects/' + func_obj.project + '/locations/us-central1',
body=req_body).execute()
pprint.pprint(response)