在云功能中使用gcloud cli [英] Using gcloud cli within a cloud function
问题描述
在云功能SDK中,SDK对GCP API的访问权限非常有限,但数量仍然有限.例如节点.
我想在云函数中调用 gcloud
cli.这可能吗?例如
gcloud sql实例修补my-database --activation-policy = NEVER
目标是每晚关闭SQL实例
我相信您应该使用 Cloud SQL Admin API .例如,如果您使用的是Python运行时,则您的需求文件和相应的客户端库,您可以使用方法来自googleapiclient.discovery导入构建的
服务=构建('sqladmin','v1beta4')projid =''#project id Cloud SQL实例所在的位置instance =''#Cloud SQL实例patch = {'settings':{'activationPolicy':'NEVER'}}req = service.instances().patch(项目= projid,instance = instance,body = patch)x = req.execute()打印(x)
There are great but still limited set of SDK access to GCP APIs within cloud function SDKs. e.g. Node.
I want to call gcloud
cli within a cloud function. Is this possible? e.g.
gcloud sql instances patch my-database --activation-policy=NEVER
The goal is nightly shutdown of an SQL instance
I believe you should use the Cloud SQL Admin API. If you're using the Python runtime for example you'd had 'google-api-python-client==1.7.8' (for example) to your requirements file and on the respective client library you would use the method instances.patch with the appropriate parameters.
Hope this helps.
Also you have here a working example with the Python runtime, just be sure to edit the 'projid' and 'instance' variables accordingly.
from googleapiclient.discovery import build
service = build('sqladmin', 'v1beta4')
projid = '' #project id where Cloud SQL instance is
instance = '' #Cloud SQL instance
patch = {'settings': {'activationPolicy':'NEVER'}}
req = service.instances().patch(project=projid, instance=instance, body=patch)
x = req.execute()
print(x)
这篇关于在云功能中使用gcloud cli的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!