如何创建一个由python库运行的云容器。云导入run_v2
我没有得到任何例子创建容器与python代码
首先,您需要在这里创建一个服务帐户和凭证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白名单在某个地方不是