【问题标题】:How To create a Cloud Run container by using Python Library?如何使用 Python 库创建 Cloud Run 容器?
【发布时间】:2022-11-03 04:31:23
【问题描述】:

如何创建一个由 py​​thon 库运行的云容器,例如 from google.cloud import run_v2,

我没有得到任何通过 python 代码创建容器的示例

【问题讨论】:

标签: python google-cloud-platform google-cloud-functions google-apis-explorer


【解决方案1】:

好吧,首先你需要在这里创建一个服务帐户和凭据https://console.cloud.google.com/apis/credentials?project=

接下来,您需要下载密钥或使用任何其他身份验证方法,在我的示例中为密钥。

# init credentials
from google.oauth2 import service_account
credentials = service_account.Credentials.from_service_account_file("prject-key.json")

# create client
import google.cloud.run_v2 as run_v2
run_client = run_v2.ServicesClient(credentials=credentials)

# build request
from google.cloud.run_v2 import ListServicesRequest
request = ListServicesRequest(
    parent="projects/{projectnumber}/locations/{location}"
)

# response
response = run_client.list_services(request=request)

您可以在这里找到样品:https://github.com/googleapis/python-run/tree/main/samples/generated_samples

另请记住,权限的工作取决于身份验证方法。 IP白名单在某处未显示

【讨论】:

    猜你喜欢
    • 2021-02-03
    • 2022-07-22
    • 2021-05-25
    • 2021-02-13
    • 2021-07-07
    • 2020-07-01
    • 2021-05-04
    • 1970-01-01
    • 2020-04-16
    相关资源
    最近更新 更多