基于 Serverless Framework 的人工智能小程序开发( 六 )

  • 将项目部署到云端,只需要通过指令serverless --debug即可:
  • ?复制代码
    DEBUG ─ Resolving the template's static variables.DEBUG ─ Collecting components from the template.DEBUG ─ Downloading any NPM components found in the template.DEBUG ─ Analyzing the template's components dependencies.DEBUG ─ Creating the template's components graph.DEBUG ─ Syncing template state.DEBUG ─ Executing the template's components graph.DEBUG ─ Starting API-Gateway deployment with name APIService in the ap-shanghai region... ...DEBUG ─ Updating configure...DEBUG ─ Created function Album_Get_Photo_Search successfulDEBUG ─ Setting tags for function Album_Get_Photo_SearchDEBUG ─ Creating trigger for function Album_Get_Photo_SearchDEBUG ─ Deployed function Album_Get_Photo_Search successfulDEBUG ─ Uploaded package successful /Users/dfounderliu/Documents/code/AIAlbum/.serverless/Album_Prediction.zipDEBUG ─ Creating function Album_PredictionDEBUG ─ Updating code...DEBUG ─ Updating configure...DEBUG ─ Created function Album_Prediction successfulDEBUG ─ Setting tags for function Album_PredictionDEBUG ─ Creating trigger for function Album_PredictionDEBUG ─ Trigger timer: timer not changedDEBUG ─ Deployed function Album_Prediction successfulConf:region:ap-shanghai... ...-path:/photo/deletemethod: ANYapiId:api-g9u6r9wq-path:/album/deletemethod: ANYapiId:api-b4c4xrq8-path:/album/addmethod: ANYapiId:api-ml6q5koy156s › APIService › done 这个过程只用了 156s 就部署了所有函数,然后打开小程序的 id 带入miniProgram目录,并且填写自己的appid在文件project.config.json的第 17 行,同时也要配置自己项目的基础目录,就是 API 网关给我们返回的地址,写在app.js的第 10 行,此时项目就可以运行起来了 。
    总结本文中的例子是通过 Serverless 架构使用 Python 语言开发了一个微信小程序,这里面涉及到了数据库的增删改查,公共组件的提取,如何定义 Components 的全局变量,如何本地调试和线上触发二者兼得,以及在什么地方初始化数据库"性价比较高" 。希望通过这样一个简单的例子,可以让 Serverless 在更多的领域都有实际的应用价值,可以给更多人灵感和启发:Serverless?万物都可以 Serverless 么?让我们一起来尝试更多 Serverless 架构的应用领域吧 。




    推荐阅读