首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何设置Google Cloud Function (Python)来创建Google Cloud Project?

如何设置Google Cloud Function (Python)来创建Google Cloud Project?
EN

Stack Overflow用户
提问于 2019-08-30 02:32:21
回答 1查看 825关注 0票数 0

我一直在使用GCP Python客户端库自动创建项目。我想实现无服务器,使用云函数和发布/订阅。我不知道如何设置依赖关系和身份验证。有人知道吗?

我从云shell运行我的python脚本,一切都正常。我尝试运行pip冻结来捕获需求,但这不起作用。

来自main.py

代码语言:javascript
复制
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

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2020-07-25 19:34:37

我可以向您展示如何计算Cloud Functions上的身份验证进度。

代码语言:javascript
复制
# for Cloud Functions use 

def get_service():
    import googleapiclient.discovery
    return googleapiclient.discovery.build('cloudresourcemanager', 'v1',  cache_discovery=False)

service = get_service()

Requirements.txt

代码语言:javascript
复制
google-api-python-client
oauth2client
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57716025

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档