在云函数中使用 gcloud cli
Using gcloud cli within a cloud function
云函数 SDK 中有大量但仍然有限的 SDK 访问 GCP API。例如节点.
我想在云函数中调用 gcloud
cli。这可能吗?例如
gcloud sql instances patch my-database --activation-policy=NEVER
目标是每晚关闭 SQL 个实例
我相信您应该使用具有适当参数的 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。
希望对您有所帮助。
这里还有一个使用 Python 运行时的工作示例,请务必相应地编辑 'projid' 和 'instance' 变量。
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)
云函数 SDK 中有大量但仍然有限的 SDK 访问 GCP API。例如节点.
我想在云函数中调用 gcloud
cli。这可能吗?例如
gcloud sql instances patch my-database --activation-policy=NEVER
目标是每晚关闭 SQL 个实例
我相信您应该使用具有适当参数的 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。
希望对您有所帮助。
这里还有一个使用 Python 运行时的工作示例,请务必相应地编辑 'projid' 和 'instance' 变量。
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)