Google cloud platform 如何设置my google cloud函数的端点路径(使用无服务器框架)
我使用无服务器框架在GCP中部署云功能,配置如下:Google cloud platform 如何设置my google cloud函数的端点路径(使用无服务器框架),google-cloud-platform,google-cloud-functions,serverless-framework,Google Cloud Platform,Google Cloud Functions,Serverless Framework,我使用无服务器框架在GCP中部署云功能,配置如下: service: myname provider: name: google stage: prod runtime: nodejs10 region: us-central1 project: myname credentials: keyfile.json environment: IS_PROD: 'true' plugins: - serverless-google-cloudfunction
service: myname
provider:
name: google
stage: prod
runtime: nodejs10
region: us-central1
project: myname
credentials: keyfile.json
environment:
IS_PROD: 'true'
plugins:
- serverless-google-cloudfunctions
package:
exclude:
- node_modules/**
- .gitignore
- .git/**
functions:
clear:
handler: clearCommand
events:
- http: clear
我使用的是无服务器google cloudfunctions
插件版本3.1.0。部署后,地址/路径如下所示:
我想知道是否有一种方法可以让我自己设定如下路径:
有没有办法设定这个?首选无服务器框架方式。对于无服务器框架,这似乎是不可能的。看这一行 deploymentName是自动生成的,没有参数覆盖它。我没有深入查看
clear
值的设置位置,但很明显,它是一个静态值
事实上,您可以在控制台中找到云函数的名称。如果您自己部署函数,您可以选择您想要的名称,从而实现您想要的链接的最后一部分是云函数名称。创建云函数是在创建云函数时完成的,如果使用创建云函数,只需引入名称即可 另一方面,如果要使用部署云功能,则必须添加参数名称,例如: gcloud函数部署my_函数--runtime=python37--trigger event=providers/cloud.firestore/eventTypes/document.write--trigger resource=projects/project_id/databases/(默认)/documents/messages/{pushId} 这将导致如下结果:
考虑到一旦命名了云函数,就可以在
serverless.yml
中的函数定义中指定名称
因此,在您的serverless.yml
中,如下所示:
functions:
clear:
name: clear
handler: clearCommand
events:
- http: clear
但是,请注意,在无服务器google cloudfunctions
3.1.0版中,函数名分配仍然存在问题。部署工作正常,GCP中部署的函数名也正确。但在执行serverless deploy
结束时,它没有正确地反映在部署状态中
编辑:
部署状态问题在版本3.1.1中已修复
在早期版本中,我们仍然需要执行以下黑客解决方法来手动更新节点单元
中的无服务器Google CloudFunctions
在info/lib/displayServiceInfo.js
中,替换当前的getFunctionNameInService
函数实现
const getFunctionNameInService = (funcName, service, stage) => {
let funcNameInService = funcName;
funcNameInService = funcNameInService.replace(service, '');
funcNameInService = funcNameInService.replace(stage, '');
funcNameInService = funcNameInService.slice(2, funcNameInService.length);
return funcNameInService;
};
与
我希望这会有所帮助。您可以根据需要命名函数;只需将name
作为参数添加到函数定义中,我在中没有看到这一点。您是否有一个示例或文档链接?
const getFunctionNameInService = (funcName, service, stage) => {
let funcNameInService = funcName;
funcNameInService = funcNameInService.replace(`${service}-`, '');
funcNameInService = funcNameInService.replace(`${stage}-, '');
return funcNameInService;
};