我一直在使用GCP Python客户端库自动创建项目。我想实现无服务器,使用云函数和发布/订阅。我不知道如何设置依赖关系和身份验证。有人知道吗?
我从云shell运行我的python脚本,一切都正常。我尝试运行pip冻结来捕获需求,但这不起作用。
来自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发布于 2020-07-25 19:34:37
我可以向您展示如何计算Cloud Functions上的身份验证进度。
# for Cloud Functions use
def get_service():
import googleapiclient.discovery
return googleapiclient.discovery.build('cloudresourcemanager', 'v1', cache_discovery=False)
service = get_service()Requirements.txt
google-api-python-client
oauth2clienthttps://stackoverflow.com/questions/57716025
复制相似问题