我在python中有一个Google Cloud函数,可以在同一项目中部署新的Google Cloud函数(从我的云存储中的.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脚本中?
谢谢!
答案 0 :(得分:2)
I wrote an article用于通过Cloud Endpoint执行此操作。
还有更多需要管理的事情,也许会在3周内向Google Cloud Next宣布。敬请期待!
答案 1 :(得分:0)
我无法解决Google Cloud功能。但是,我找到了针对Firebase函数的解决方案。您可以在这里的问题中找到它: Rate limiting for Google/Firebase cloud functions?