{"componentChunkName":"component---src-templates-blog-detail-tsx","path":"/blog/2020-03-30-serverless-cvm","result":{"data":{"currentBlog":{"id":"173c900b-90b8-5608-842a-3f0b158f2e83","frontmatter":{"thumbnail":"https://img.serverlesscloud.cn/2020522/1590162499020-%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_15901624529568.png","authors":["KaliArch"],"categories":["user-stories"],"date":"2020-03-30T00:00:00.000Z","title":"Serverless + CVM 实战","description":"Tencent Serverless Toolkit for VS Code 小试牛刀，本次示例利用腾讯云函数 SCF 简单示例下 Serverless 的一小部分功能。","authorslink":["https://cloud.tencent.com/developer/article/1606440"],"translators":null,"translatorslink":null,"tags":["Serverless","CVM"],"keywords":"Serverless,Serverless网站,Serverless应用","outdated":null},"wordCount":{"words":214,"sentences":50,"paragraphs":50},"fileAbsolutePath":"/opt/build/repo/content/blog/2020-03-30-serverless-cvm.md","fields":{"slug":"/blog/2020-03-30-serverless-cvm/","keywords":["java","serverless","spa","云函数","serverless","serverlesscloud","Serverless"]},"html":"<p>之前了解过 Tencent Serverless Toolkit for VS Code 的IDE 插件，刚好借此使用下，相较于之前没有 IDE 插件，编码在本地，但是 debug 非常繁琐，需要上传代码到云端控制台操作，现在有了 IDE 插件从本地编码测试上传部署一条路，快速体验下此为 SCF 添翼的神器。</p>\n<p>接下来看看 Serverless + CVM 实战</p>\n<h2 id=\"项目背景\"><a href=\"#%E9%A1%B9%E7%9B%AE%E8%83%8C%E6%99%AF\" aria-label=\"项目背景 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>项目背景</h2>\n<p>目前有客户有需求对数量众多的测试环境想通过非工作时间进行关机操作，同时腾讯提供关机不收费的 CVM 操作，一定程度可以节省 IT 开支，每天早上工作时间提前进行开机，如此如果人工来操作重复周期性的操作显然非常不合适，但是共有云目前没有提供这种对服务器定时开关机操作的产品功能，只能利用其 API 来进行，但是需要一台具备公网能力的服务器来发起API调用请求，此时刚好利用 Serverless 的 Tencent Serverless Toolkit for VS Code 小试牛刀，本次示例利用腾讯云函数（SCF）简单示例下 Serverless 的一小部分功能。</p>\n<p>之前由于没有IDE，将程序部署到SCF后运行不便与调试，现在有了神器Tencent Serverless Toolkit for VS Code，简单方便的本地配置，快速拉取云端函数并可以在本地模拟<a href=\"https://cloud.tencent.com/product/cos?from=10680\">COS</a>，CMQ，API网关等出发事件运行还书，本地化的开发，调试，可谓补齐了SCF不便于代码上传调试的缺点，利用此插件可在本地快捷调试代码，一键上传程序，为SCF如虎添翼。</p>\n<h2 id=\"项目编写\"><a href=\"#%E9%A1%B9%E7%9B%AE%E7%BC%96%E5%86%99\" aria-label=\"项目编写 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>项目编写</h2>\n<h3 id=\"1-根据模版创建项目\"><a href=\"#1-%E6%A0%B9%E6%8D%AE%E6%A8%A1%E7%89%88%E5%88%9B%E5%BB%BA%E9%A1%B9%E7%9B%AE\" aria-label=\"1 根据模版创建项目 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>1. 根据模版创建项目</h3>\n<p><img src=\"https://img.serverlesscloud.cn/2020522/1590162499364-%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_15901624529568.png\" alt=\"serverless\"></p>\n<h3 id=\"2-填写项目名称\"><a href=\"#2-%E5%A1%AB%E5%86%99%E9%A1%B9%E7%9B%AE%E5%90%8D%E7%A7%B0\" aria-label=\"2 填写项目名称 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>2. 填写项目名称</h3>\n<p>填写项目名称完成项目创建</p>\n<p><img src=\"https://img.serverlesscloud.cn/2020522/1590162499985-%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_15901624529568.png\" alt=\"serverless\"></p>\n<h3 id=\"3-了解项目结构\"><a href=\"#3-%E4%BA%86%E8%A7%A3%E9%A1%B9%E7%9B%AE%E7%BB%93%E6%9E%84\" aria-label=\"3 了解项目结构 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>3. 了解项目结构</h3>\n<p>在项目模版中，主要关注index.py 和template.yaml</p>\n<ul>\n<li>Index.py 为业务逻辑代码</li>\n<li>\n<p>Template.yaml 为腾讯云SCF配置相关，如下为我的定时任务配置</p>\n<p>为提高安全性其中由于使用的了腾讯云的secretid/secretkey，将其作为变量放置在配置中，业务代码从配置中获取，</p>\n<p>其中也配置了超时时间以及定时cron</p>\n</li>\n</ul>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"13178061061871626000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"代码复制成功\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`Resources:\n  default:\n    Type: TencentCloud::Serverless::Namespace\n    cvm_oper:\n      Properties:\n        CodeUri: .\n        Description: cvm oper\n        Environment:\n          Variables:\n            secretid: AKIDZyGxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n            secretkey: kFUTDkxxxxxxxxxxxxxxxxxxxxxxxx\n        Events:\n          stop_cvm:\n            Properties:\n              CronExpression: 0 59 11 * * MON-FRI *\n              Enable: true\n            Type: Timer\n        Handler: index.main_handler\n        MemorySize: 128\n        Runtime: Python3.6\n        Timeout: 10\n        VpcConfig:\n          SubnetId: ''\n          VpcId: ''\n      Type: TencentCloud::Serverless::Function`, `13178061061871626000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                复制代码<svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">Resources<span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">default</span><span class=\"token punctuation\">:</span>\n    Type<span class=\"token punctuation\">:</span> TencentCloud<span class=\"token punctuation\">:</span><span class=\"token punctuation\">:</span>Serverless<span class=\"token punctuation\">:</span><span class=\"token punctuation\">:</span>Namespace\n    cvm_oper<span class=\"token punctuation\">:</span>\n      Properties<span class=\"token punctuation\">:</span>\n        CodeUri<span class=\"token punctuation\">:</span> <span class=\"token punctuation\">.</span>\n        Description<span class=\"token punctuation\">:</span> cvm oper\n        Environment<span class=\"token punctuation\">:</span>\n          Variables<span class=\"token punctuation\">:</span>\n            secretid<span class=\"token punctuation\">:</span> AKIDZyGxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n            secretkey<span class=\"token punctuation\">:</span> kFUTDkxxxxxxxxxxxxxxxxxxxxxxxx\n        Events<span class=\"token punctuation\">:</span>\n          stop_cvm<span class=\"token punctuation\">:</span>\n            Properties<span class=\"token punctuation\">:</span>\n              CronExpression<span class=\"token punctuation\">:</span> <span class=\"token number\">0</span> <span class=\"token number\">59</span> <span class=\"token number\">11</span> <span class=\"token operator\">*</span> <span class=\"token operator\">*</span> <span class=\"token constant\">MON</span><span class=\"token operator\">-</span><span class=\"token constant\">FRI</span> <span class=\"token operator\">*</span>\n              Enable<span class=\"token punctuation\">:</span> <span class=\"token boolean\">true</span>\n            Type<span class=\"token punctuation\">:</span> Timer\n        Handler<span class=\"token punctuation\">:</span> index<span class=\"token punctuation\">.</span>main_handler\n        MemorySize<span class=\"token punctuation\">:</span> <span class=\"token number\">128</span>\n        Runtime<span class=\"token punctuation\">:</span> Python3<span class=\"token punctuation\">.</span><span class=\"token number\">6</span>\n        Timeout<span class=\"token punctuation\">:</span> <span class=\"token number\">10</span>\n        VpcConfig<span class=\"token punctuation\">:</span>\n          SubnetId<span class=\"token punctuation\">:</span> <span class=\"token string\">''</span>\n          VpcId<span class=\"token punctuation\">:</span> <span class=\"token string\">''</span>\n      Type<span class=\"token punctuation\">:</span> TencentCloud<span class=\"token punctuation\">:</span><span class=\"token punctuation\">:</span>Serverless<span class=\"token punctuation\">:</span><span class=\"token punctuation\">:</span>Function</code></pre></div>\n<p><img src=\"https://img.serverlesscloud.cn/2020522/1590162499091-%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_15901624529568.png\" alt=\"serverless\"></p>\n<h2 id=\"编写代码\"><a href=\"#%E7%BC%96%E5%86%99%E4%BB%A3%E7%A0%81\" aria-label=\"编写代码 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>编写代码</h2>\n<h3 id=\"1-代码程序\"><a href=\"#1-%E4%BB%A3%E7%A0%81%E7%A8%8B%E5%BA%8F\" aria-label=\"1 代码程序 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>1. 代码程序</h3>\n<p>在此我利用腾讯云的<a href=\"https://cloud.tencent.com/product/cvm?from=10680\">CVM</a>的SDK进行了<a href=\"https://cloud.tencent.com/product/cvm?from=10680\">云服务器</a>的停止与开机操作，在此简单实例下cvm启动</p>\n<p><img src=\"https://img.serverlesscloud.cn/2020522/1590162499924-%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_15901624529568.png\" alt=\"serverless\"></p>\n<p>其中有event，正式环境可以为其传入自己业务需求的参数来处理具体业务逻辑。</p>\n<h3 id=\"2-本地测试\"><a href=\"#2-%E6%9C%AC%E5%9C%B0%E6%B5%8B%E8%AF%95\" aria-label=\"2 本地测试 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>2. 本地测试</h3>\n<p>在本地 IDE 进行运行测试</p>\n<p><img src=\"https://img.serverlesscloud.cn/2020522/1590162499968-%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_15901624529568.png\" alt=\"serverless\"></p>\n<p>查看以及运行成功，服务器也正常启动</p>\n<p><img src=\"https://img.serverlesscloud.cn/2020522/1590162498615-%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_15901624529568.png\" alt=\"serverless\"></p>\n<h2 id=\"上传项目到云端\"><a href=\"#%E4%B8%8A%E4%BC%A0%E9%A1%B9%E7%9B%AE%E5%88%B0%E4%BA%91%E7%AB%AF\" aria-label=\"上传项目到云端 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>上传项目到云端</h2>\n<h3 id=\"1-上传到云端进行测试\"><a href=\"#1-%E4%B8%8A%E4%BC%A0%E5%88%B0%E4%BA%91%E7%AB%AF%E8%BF%9B%E8%A1%8C%E6%B5%8B%E8%AF%95\" aria-label=\"1 上传到云端进行测试 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>1. 上传到云端进行测试</h3>\n<p><img src=\"https://img.serverlesscloud.cn/2020522/1590162498739-%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_15901624529568.png\" alt=\"serverless\"></p>\n<h3 id=\"2-云端查看项目\"><a href=\"#2-%E4%BA%91%E7%AB%AF%E6%9F%A5%E7%9C%8B%E9%A1%B9%E7%9B%AE\" aria-label=\"2 云端查看项目 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>2. 云端查看项目</h3>\n<p><img src=\"https://img.serverlesscloud.cn/2020522/1590162498573-%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_15901624529568.png\" alt=\"serverless\"></p>\n<p><img src=\"https://img.serverlesscloud.cn/2020522/1590162498717-%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_15901624529568.png\" alt=\"serverless\"></p>\n<p><img src=\"https://img.serverlesscloud.cn/2020522/1590162500055-%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_15901624529568.png\" alt=\"serverless\"></p>\n<h2 id=\"云端测试\"><a href=\"#%E4%BA%91%E7%AB%AF%E6%B5%8B%E8%AF%95\" aria-label=\"云端测试 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>云端测试</h2>\n<p><img src=\"https://img.serverlesscloud.cn/2020522/1590162498671-%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_15901624529568.png\" alt=\"serverless\"></p>\n<h2 id=\"查看运行日志\"><a href=\"#%E6%9F%A5%E7%9C%8B%E8%BF%90%E8%A1%8C%E6%97%A5%E5%BF%97\" aria-label=\"查看运行日志 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>查看运行日志</h2>\n<p><img src=\"https://img.serverlesscloud.cn/2020522/1590162499020-%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_15901624529568.png\" alt=\"serverless\"></p>\n<p>至此我们以及利用Tencent Serverless Toolkit for VS Cod完成了简单的项目编写部署，在此只是抛砖引玉，实际代码需要考虑到传入参数，多项目协调部署等。</p>\n<h2 id=\"思考\"><a href=\"#%E6%80%9D%E8%80%83\" aria-label=\"思考 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>思考</h2>\n<p>从裸金属物理服务器到虚拟化平台，再到云服务器，现在到容器技术，Serverless 以函数为扩展单位，虚拟化运行时环境 （Runtime）。是现有计算资源的最小单位，具有完全自动、一键部署、高度可扩展等特点。开发者在构建和运行应用时无需管理服务器等基础设施，应用被解耦为细粒度的函数，函数是部署和运行的基本单位。用户只为实际使用的资源付费。</p>\n<p>拥有了 Tencent Serverless Toolkit for VS Code，对于 SCF 如鱼得水，本地化代码编写测试上传部署一条龙，配置也托管在代码中，无需在登录云平台进行配置，config as code 模式大大提升了 SCF 的效率，简化操作，适用于开发人员。</p>\n<p>在此只是最简单的试用了一下 SCF，其更强大的功能及优势在云计算的潮流下后期会越显明显，适用场景众多，业务进行拆分，分工更加精细。截取官网的一张最常用的移动与 WEB 应用图，业务各模块分离，函数具有<a href=\"https://cloud.tencent.com/product/as?from=10680\">弹性伸缩</a>，前端入口为各业务模块的 API 网关，配合 CDB/COS 完成总体架构。</p>\n<blockquote>\n<p>参考链接：<a href=\"https://cloud.tencent.com/act/event/vscode?from=10680\">https://cloud.tencent.com/act/event/vscode</a></p>\n</blockquote>\n<hr>\n<div id='scf-deploy-iframe-or-md'></div>\n<hr>\n<blockquote>\n<p><strong>传送门：</strong></p>\n<ul>\n<li>GitHub: <a href=\"https://github.com/serverless/serverless/blob/master/README_CN.md\">github.com/serverless</a></li>\n<li>官网：<a href=\"https://serverless.com/\">serverless.com</a></li>\n</ul>\n</blockquote>\n<p>欢迎访问：<a href=\"https://serverlesscloud.cn/\">Serverless 中文网</a>，您可以在 <a href=\"https://serverlesscloud.cn/best-practice\">最佳实践</a> 里体验更多关于 Serverless 应用的开发！</p>","tableOfContents":"<ul>\n<li><a href=\"/blog/2020-03-30-serverless-cvm/#%E9%A1%B9%E7%9B%AE%E8%83%8C%E6%99%AF\">项目背景</a></li>\n<li>\n<p><a href=\"/blog/2020-03-30-serverless-cvm/#%E9%A1%B9%E7%9B%AE%E7%BC%96%E5%86%99\">项目编写</a></p>\n<ul>\n<li><a href=\"/blog/2020-03-30-serverless-cvm/#1-%E6%A0%B9%E6%8D%AE%E6%A8%A1%E7%89%88%E5%88%9B%E5%BB%BA%E9%A1%B9%E7%9B%AE\">1. 根据模版创建项目</a></li>\n<li><a href=\"/blog/2020-03-30-serverless-cvm/#2-%E5%A1%AB%E5%86%99%E9%A1%B9%E7%9B%AE%E5%90%8D%E7%A7%B0\">2. 填写项目名称</a></li>\n<li><a href=\"/blog/2020-03-30-serverless-cvm/#3-%E4%BA%86%E8%A7%A3%E9%A1%B9%E7%9B%AE%E7%BB%93%E6%9E%84\">3. 了解项目结构</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"/blog/2020-03-30-serverless-cvm/#%E7%BC%96%E5%86%99%E4%BB%A3%E7%A0%81\">编写代码</a></p>\n<ul>\n<li><a href=\"/blog/2020-03-30-serverless-cvm/#1-%E4%BB%A3%E7%A0%81%E7%A8%8B%E5%BA%8F\">1. 代码程序</a></li>\n<li><a href=\"/blog/2020-03-30-serverless-cvm/#2-%E6%9C%AC%E5%9C%B0%E6%B5%8B%E8%AF%95\">2. 本地测试</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"/blog/2020-03-30-serverless-cvm/#%E4%B8%8A%E4%BC%A0%E9%A1%B9%E7%9B%AE%E5%88%B0%E4%BA%91%E7%AB%AF\">上传项目到云端</a></p>\n<ul>\n<li><a href=\"/blog/2020-03-30-serverless-cvm/#1-%E4%B8%8A%E4%BC%A0%E5%88%B0%E4%BA%91%E7%AB%AF%E8%BF%9B%E8%A1%8C%E6%B5%8B%E8%AF%95\">1. 上传到云端进行测试</a></li>\n<li><a href=\"/blog/2020-03-30-serverless-cvm/#2-%E4%BA%91%E7%AB%AF%E6%9F%A5%E7%9C%8B%E9%A1%B9%E7%9B%AE\">2. 云端查看项目</a></li>\n</ul>\n</li>\n<li><a href=\"/blog/2020-03-30-serverless-cvm/#%E4%BA%91%E7%AB%AF%E6%B5%8B%E8%AF%95\">云端测试</a></li>\n<li><a href=\"/blog/2020-03-30-serverless-cvm/#%E6%9F%A5%E7%9C%8B%E8%BF%90%E8%A1%8C%E6%97%A5%E5%BF%97\">查看运行日志</a></li>\n<li><a href=\"/blog/2020-03-30-serverless-cvm/#%E6%80%9D%E8%80%83\">思考</a></li>\n</ul>"},"previousBlog":{"id":"e3cbde67-2160-5b99-888c-06285ca68253","frontmatter":{"thumbnail":"https://img.serverlesscloud.cn/2020522/1590167093112-%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_15901670801318.png","authors":["逸笙"],"categories":["user-stories"],"date":"2020-03-31T00:00:00.000Z","title":"云函数 SCF 中 PHP 的一些入门坑","description":"由于云函数本身是用 bootstrap.php 来调用我们的入口函数，默认为 index.main\\_handler，意思是调用 index.php 文件中的 main\\_handler()，所以很多地方写法要有改变。php 一般提供网页服务，所以我主要讲 API 网关配合的 SCF。","authorslink":["https://cloud.tencent.com/developer/article/1607248"],"translators":null,"translatorslink":null,"tags":["Serverless","云函数"],"keywords":"Serverless,Serverless PHP,Serverless应用","outdated":null},"wordCount":{"words":213,"sentences":31,"paragraphs":31},"fileAbsolutePath":"/opt/build/repo/content/blog/2020-03-31-scf-php.md","fields":{"slug":"/blog/2020-03-31-scf-php/","keywords":["go","java","php","serverless","云函数","event","浏览器","网关","headers","substr"]}},"nextBlog":{"id":"4a554b43-e338-5771-87e3-00f09d2d64d8","frontmatter":{"thumbnail":"https://img.serverlesscloud.cn/2020522/1590160217283-%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_15901601368204.png","authors":["jessy"],"categories":["user-stories"],"date":"2020-03-30T00:00:00.000Z","title":"静态网站利用 SCF+API 访问自定义后端接口","description":"本文介绍使用全静态页面的网站如何利用腾讯云的 SCF+API 服务实现简单的后端接口，并提供了一个 Python 出题器的实例演示。","authorslink":["https://cloud.tencent.com/developer/article/1606163"],"translators":null,"translatorslink":null,"tags":["Serverless","云函数"],"keywords":"Serverless,Serverless网站,Serverlessdays应用","outdated":null},"wordCount":{"words":297,"sentences":40,"paragraphs":40},"fileAbsolutePath":"/opt/build/repo/content/blog/2020-03-30-serverless-website.md","fields":{"slug":"/blog/2020-03-30-serverless-website/","keywords":["go","java","nodejs","php","python","serverless","无服务器","云函数","limit","创建","密钥"]}},"recommendBlogs":{"edges":[{"node":{"id":"4300b21c-7209-5256-86ff-0d38e3daec9b","frontmatter":{"thumbnail":"https://main.qcloudimg.com/raw/14f1c8eed372e76c1b139703b2f6d0fa.jpg","authors":["KieranMcCarthy"],"categories":["user-stories","engineering-culture"],"date":"2018-01-09T00:00:00.000Z","title":"我是如何在四年时间里，从厨师转行为 Serverless 应用开发者","description":"我是厨师出身，现在成为了一名 Serverless 应用开发者。","authorslink":["https://serverless.com/author/kieranmccarthy/"],"translators":["Aceyclee"],"translatorslink":["https://www.zhihu.com/people/Aceyclee"],"tags":["应用开发","Serverless"],"keywords":"Serverless 应用开发,Serverless 管理,厨师转行为 Serverless 应用开发者","outdated":null},"wordCount":{"words":285,"sentences":38,"paragraphs":36},"fileAbsolutePath":"/opt/build/repo/content/blog/2018-01-09-from-chef-to-serverless-developer-in-4-years.md","fields":{"slug":"/blog/2018-01-09-from-chef-to-serverless-developer-in-4-years/","keywords":["无服务器","无服务器开发","云函数","学习","Serverless","构建","Framework","开发者","服务器","应用","学位","简历"]}}},{"node":{"id":"713a0563-4bf9-5721-bacb-3b4ef609fe4a","frontmatter":{"thumbnail":"https://s3-us-west-2.amazonaws.com/assets.blog.serverless.com/camp-fire/camp-fire-housing-thumb.jpg","authors":["EricWyne"],"categories":["guides-and-tutorials","user-stories"],"date":"2018-12-05T00:00:00.000Z","title":"Serverless Twitter 机器人帮助为坎普山火受灾者安置住房","description":"加利福尼亚州的坎普山火致使数千人流离失所，为此，我构建了一个简单的 Serverless Twitter 机器人来帮助将受灾者安置在临时住房！","authorslink":["https://serverless.com/author/ericwyne/"],"translators":["Aceyclee"],"translatorslink":["zhihu.com/people/Aceyclee"],"tags":null,"keywords":null,"outdated":null},"wordCount":{"words":157,"sentences":26,"paragraphs":26},"fileAbsolutePath":"/opt/build/repo/content/blog/2018-12-05-serverless-twitter-camp-fire.md","fields":{"slug":"/blog/2018-12-05-serverless-twitter-camp-fire/","keywords":["serverless","无服务器","云函数","Serverless","org","住房","Twitter","函数","受灾","机器人","山火"]}}},{"node":{"id":"98602143-b837-5f50-a24f-3b1ec76044d7","frontmatter":{"thumbnail":"https://s3-us-west-2.amazonaws.com/assets.blog.serverless.com/sqquid/sqquid-serverless-thumb.jpg","authors":["RonPeled"],"categories":["user-stories"],"date":"2018-12-17T00:00:00.000Z","title":"SQQUID：100% 无服务器初创公司","description":"SQQUID 将 AWS Lambda 和无服务器框架用于其核心产品和营销网站。我们来看看一个完全无服务器的初创公司是怎样的。","authorslink":null,"translators":null,"translatorslink":null,"tags":null,"keywords":null,"outdated":null},"wordCount":{"words":266,"sentences":42,"paragraphs":42},"fileAbsolutePath":"/opt/build/repo/content/blog/2018-12-17-sqquid-one-hundred-percent-serverless.md","fields":{"slug":"/blog/2018-12-17-sqquid-one-hundred-percent-serverless/","keywords":["go","serverless","无服务器","无服务器架构","服务器","架构","Lambda","集成","FaaS","串行","系统"]}}},{"node":{"id":"29dc2e58-d2ba-56f9-aee1-d21b0bc62e0e","frontmatter":{"thumbnail":"https://s3-us-west-2.amazonaws.com/assets.blog.serverless.com/ao-com-story/ao-serverless-thumbnail.png","authors":["NickGottlieb"],"categories":["user-stories"],"date":"2019-04-24T00:00:00.000Z","title":"AO.com：逐渐转向无服务器优先","description":"AO.com 的 SCV 团队率先尝试无服务器服务。折服于无服务器框架的快速周转时间和低维护成本，整个团队逐渐转向无服务器优先。","authorslink":null,"translators":null,"translatorslink":null,"tags":null,"keywords":null,"outdated":null},"wordCount":{"words":236,"sentences":42,"paragraphs":35},"fileAbsolutePath":"/opt/build/repo/content/blog/2019-04-24-ao-serverless-first.md","fields":{"slug":"/blog/2019-04-24-ao-serverless-first/","keywords":["serverless","无服务器","服务器","团队","Lambda","功能","构建"]}}},{"node":{"id":"752d08d1-387a-5bde-acf3-98141baab294","frontmatter":{"thumbnail":"https://img.serverlesscloud.cn/2020414/1586871710979-%E5%85%AC%E5%85%B1%E7%94%A8.png","authors":["Anycodes"],"categories":["user-stories"],"date":"2019-06-20T00:00:00.000Z","title":"如何用 Serverless 为 Python 云函数打包依赖","description":"在使用无服务器云函数SCF时通常会遇到导入第三方库的问题，很多小伙伴比较头疼是：应该如何打包进去？这里，推荐几个不错的方法。","authorslink":["https://zhuanlan.zhihu.com/ServerlessGo"],"translators":null,"translatorslink":null,"tags":["云函数","Serverless"],"keywords":"Serverless,Serverless应用,无服务器云函数","outdated":null},"wordCount":{"words":81,"sentences":43,"paragraphs":43},"fileAbsolutePath":"/opt/build/repo/content/blog/2019-06-20-for-python-cloud-functions.md","fields":{"slug":"/blog/2019-06-20-for-python-cloud-functions/","keywords":["java","serverless","无服务器","无服务器云函数","云函数","serverlesscloud","安装","serverless","pillowtest"]}}},{"node":{"id":"2dc78814-9d77-555b-a1bb-ad202c8ec2d1","frontmatter":{"thumbnail":"https://s3-us-west-2.amazonaws.com/assets.blog.serverless.com/cloudforecast/thumbnail.png","authors":["FrancoisLagier"],"categories":["user-stories"],"date":"2019-08-07T00:00:00.000Z","title":"Serverless：初创企业的理想选择？（CloudForecast 案例分析）","description":"CloudForecast 是 2018 年成立的一家独立初创企业，本文将介绍他们决定选择 Serverless 的原因。","authorslink":["https://serverless.com/author/francoislagier/"],"translators":["Aceyclee"],"translatorslink":["zhihu.com/people/Aceyclee"],"tags":null,"keywords":null,"outdated":null},"wordCount":{"words":211,"sentences":29,"paragraphs":29},"fileAbsolutePath":"/opt/build/repo/content/blog/2019-08-07-serverless-for-startups.md","fields":{"slug":"/blog/2019-08-07-serverless-for-startups/","keywords":["serverless","云函数","serverless","函数","Serverless","utm","Framework","blog","CloudForecast","cloudforecast"]}}},{"node":{"id":"97450b07-658b-5207-8216-1c7b9b51b115","frontmatter":{"thumbnail":"https://img.serverlesscloud.cn/2020114/1578988490344-v2-8b2cd2c5275aa2c5a3c5083a148a7a9f_1200x500.jpg","authors":["Anycodes"],"categories":["user-stories"],"date":"2019-09-01T00:00:00.000Z","title":"如何通过 Serverless 与自然语言处理，让搜索引擎「看」到你的博客","description":"Serverless 与自然语言处理结合的一个小应用","authorslink":["https://www.zhihu.com/people/liuyu-43-97"],"translators":null,"translatorslink":null,"tags":["个人博客","serverless"],"keywords":"Serverless 自然语言处理","outdated":null},"wordCount":{"words":106,"sentences":34,"paragraphs":34},"fileAbsolutePath":"/opt/build/repo/content/blog/2019-09-01-search-engine-blog.md","fields":{"slug":"/blog/2019-09-01-search-engine-blog/","keywords":["serverless","云函数","keywords","serverlesscloud","summary"]}}},{"node":{"id":"ae4fd2f8-515c-5aec-b584-38427ef33f7e","frontmatter":{"thumbnail":"https://img.serverlesscloud.cn/2020114/1578989800047-part-00492-780.jpg","authors":["Anycodes"],"categories":["guides-and-tutorials","user-stories"],"date":"2019-09-16T00:00:00.000Z","title":"突破传统 OJ 瓶颈，「判题姬」接入云函数","description":"通过 Serverless 实现在线编程","authorslink":["https://www.zhihu.com/people/liuyu-43-97"],"translators":null,"translatorslink":null,"tags":["在线编程","云函数"],"keywords":"Serverless 在线编程,Serverless OJ","outdated":null},"wordCount":{"words":169,"sentences":30,"paragraphs":30},"fileAbsolutePath":"/opt/build/repo/content/blog/2019-09-16-online-Judge.md","fields":{"slug":"/blog/2019-09-16-online-Judge/","keywords":["python","serverless","云函数","代码","函数","serverless"]}}}],"totalCount":64}},"pageContext":{"isCreatedByStatefulCreatePages":false,"blogId":"173c900b-90b8-5608-842a-3f0b158f2e83","previousBlogId":"e3cbde67-2160-5b99-888c-06285ca68253","nextBlogId":"4a554b43-e338-5771-87e3-00f09d2d64d8","categories":["user-stories"]}}}