我在python中具有Google云功能,可以在同一项目中部署新的Google云功能(从我的云存储的.zip文件中部署)。这些函数包含以下代码:
import requests
import json
def make_func(request):
# Get the access token from the metadata server
metadata_server_token_url = 'http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token?scopes=https://www.googleapis.com/auth/cloud-platform'
token_request_headers = {'Metadata-Flavor': 'Google'}
token_response = requests.get(metadata_server_token_url, headers=token_request_headers)
token_response_decoded = token_response.content.decode("utf-8")
jwt = json.loads(token_response_decoded)['access_token']
# Use the api you mentioned to create the function
response = requests.post('https://cloudfunctions.googleapis.com/v1/projects/my-project/locations/us-central1/functions',
json={"name":"projects/my-project/locations/us-central1/functions/funct","runtime":"python37","sourceArchiveUrl":"gs://functions/main.zip","entryPoint":"hello_world","httpsTrigger": {} },
headers={'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Bearer {}'.format(jwt)} )
if response:
return 'Success! Function Created'
else:
return str(response.json())
我想添加一些配额/限制这些新功能。这可以是调用次数,调用/分钟,在此功能上花费的费用,等等。您知道如何添加配额吗?以及如何将其添加到我的Python脚本中?
谢谢!
I wrote an article用于通过Cloud Endpoint执行此操作。
将有更多可管理的内容,也许会在3周内向Google Cloud Next宣布。敬请期待!