我一直在使用GCP Python客户端库来自动创建项目。我想无服务器使用Cloud Functions和Pub / Sub。我不知道如何设置依赖关系和身份验证。有人知道吗
我从云外壳运行了python脚本,一切正常。我尝试运行点冻结来捕获需求,但这没有用。
来自main.py
from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
GOOGLE_APPLICATION_CREDENTIALS = "./credentials.json"
credentials = GoogleCredentials.get_application_default()
def call_function(event, context):
service_proj_body = {
"name": "gcp-functiontest30",
"projectId": "gcp-functiontest30",
"parent": {
"id": '750256061723',
"type": "organization"
}
}
"""Background Cloud Function to be triggered by Pub/Sub.
Args:
event (dict): The dictionary with data specific to this type of
event. The `data` field contains the PubsubMessage message. The
`attributes` field will contain custom attributes if there are any.
context (google.cloud.functions.Context): The Cloud Functions event
metadata. The `event_id` field contains the Pub/Sub message ID. The
`timestamp` field contains the publish time.
"""
print("""This Function was triggered by messageId {} published at {}
""".format(context.event_id, context.timestamp))
if 'data' in event:
service = discovery.build(
'cloudresourcemanager', 'v1', credentials=GOOGLE_APPLICATION_CREDENTIALS)
request = service.projects().create(body=service_proj_body)
response = request.execute()
print(response)
else:
print('Sorry.')
我的部署的云功能error logs遇到很多错误
Requirements.txt
google-api-core==1.14.2
google-api-python-client==1.7.11
google-auth==1.6.3
google-auth-httplib2==0.0.3
google-auth-oauthlib==0.4.0
google-cloud-core==1.0.3
google-cloud-logging==1.12.1
google-cloud-resource-manager
google-pasta==0.1.7
google-resumable-media==0.3.2
googleapis-common-protos==1.6.0
grpc-google-iam-v1==0.12.3
Flask==0.10.1
httplib2==0.13.1
Markdown==2.5.2
oauth2client==4.1.3
oauthlib==3.1.0
pathlib2==2.3.4
requests==2.22.0
requests-oauthlib==1.2.0
uritemplate
WebTest
pycrypto
pyopenssl
答案 0 :(得分:0)
我可以向您展示如何确定Cloud Functions上的身份验证进度。
double
Requirements.txt
QApplication.setApplicationName("my-name")