{"componentChunkName":"component---src-templates-blog-detail-tsx","path":"/blog/2020-03-16-serverlesspython","result":{"data":{"currentBlog":{"id":"59a44895-3215-5ad0-8f99-9da7ee04ecdd","frontmatter":{"thumbnail":"https://img.serverlesscloud.cn/2020326/1585234124615-0.jpg","authors":["serverless 社区"],"categories":["user-stories","engineering-culture"],"date":"2020-03-16T00:00:00.000Z","title":"Serverless Python 开发实战（附源码）","description":"本文将为大家详细讲解 Serverless 架构的处理规范与处理模型、典型的工作流程，以及 Serverless 工程化的难点与挑战，最后将结合 Python Flask + Serverless 的情人节表白页制作实例","authorslink":null,"translators":null,"translatorslink":null,"tags":["Serverless","Python"],"keywords":"serverless发展,Serverless 基本概念,Serverless生产力","outdated":true},"wordCount":{"words":590,"sentences":104,"paragraphs":104},"fileAbsolutePath":"/opt/build/repo/content/blog/2020-03-16-serverlesspython.md","fields":{"slug":"/blog/2020-03-16-serverlesspython/","keywords":["serverless","无服务器","云函数","云原生","Serverless","事件","Python","函数"]},"html":"<p>Python是一种热门的编程语言，Serverless 是近年来迅速兴起的一个技术概念，基于 Serverless 架构能构建出多种应用场景，适用于各行各业。</p>\n<p>本文将为大家详细讲解 Serverless 架构的处理规范与处理模型、典型的工作流程，以及 Serverless 工程化的难点与挑战。最后将结合 Python Flask + Serverless 的情人节表白页制作实例，展示如何用 Serverless 的方式进行 Python 编程，将热门Python 框架利用Serverless 快速上云。</p>\n<p>文章整理自 Serverless Framework 技术专家陈涛在腾讯云大学的视频分享。</p>\n<p>本次分享大纲如下：</p>\n<ol>\n<li>Serverless的架构规范 </li>\n<li>Serverless的事件与规范 </li>\n<li>Serverless工程化的难点与挑战 </li>\n<li>使用Python Flask 开发情人节表白页</li>\n</ol>\n<h2 id=\"一、serverless-的架构规范\"><a href=\"#%E4%B8%80%E3%80%81serverless-%E7%9A%84%E6%9E%B6%E6%9E%84%E8%A7%84%E8%8C%83\" aria-label=\"一、serverless 的架构规范 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>一、Serverless 的架构规范</h2>\n<h3 id=\"1、serverless-web-场景处理的典型结构\"><a href=\"#1%E3%80%81serverless-web-%E5%9C%BA%E6%99%AF%E5%A4%84%E7%90%86%E7%9A%84%E5%85%B8%E5%9E%8B%E7%BB%93%E6%9E%84\" aria-label=\"1、serverless web 场景处理的典型结构 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><strong>1、Serverless Web 场景处理的典型结构</strong></h3>\n<p>如下图所示，一般的 Web\n场景无非通过客户端，到服务器，然后服务器去调用数据库，这是最常用的一个简单\nWeb 场景，那么 Serverless\n把服务器完全拆解，比如可能会分为两块内容，第一块是鉴权系统，第二块是 API\n网关，其实 API 网关和鉴权系统都算 BaaS 里的东西，最后是 FaaS\n就是函数，我们通过函数去调用数据库来实现普通的 Web 场景的使用。</p>\n<p>这里有一个思考，就是 Serverless\n到底为我们做了一些什么，在这个典型架构中为我们做的就是及时扩容服务器、代码是否健康运行、防止黑客攻击服务器等一系列的运维操作。</p>\n<p>从下面两个架构图中就可以非常粗浅认知 Serverless 其实是有两个部分：</p>\n<ul>\n<li>第一个是 FaaS 就是计算层，这一块就对应云函数。</li>\n<li>第二个是 BaaS，其中包括 API\n网关、身份验证、对象存储，还有时间触发等。</li>\n</ul>\n<p><img src=\"https://img.serverlesscloud.cn/2020326/1585233027593-%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_15852330258136.png\" alt=\"Python\"></p>\n<h3 id=\"2、serverless处理模型\"><a href=\"#2%E3%80%81serverless%E5%A4%84%E7%90%86%E6%A8%A1%E5%9E%8B\" aria-label=\"2、serverless处理模型 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><strong>2、Serverless处理模型</strong></h3>\n<p>事件源通过同步或异步来调用被调函数，然后 FaaS\n做一些平台化的服务，包括身份、数据、鉴权等，这是典型的 FaaS\n解决方案示意图。</p>\n<p>从下图我们可以非常粗浅了解到一个概念调用，函数最关键的概念是调用，就是事件源去调用函数，然后来完成我们一系列的操作。</p>\n<p>状态/运行时是在电脑上所描述的运行执行环境，比方说我们平常用的Python、PHP、Node.js\n都是有运行时，就是这个函数在运行时间内所做的一些环境的搭建或者处理。</p>\n<p>这是我们 Serverless\n处理的一个简单模型，我们在里面可以知道是有同步或者异步的调用。</p>\n<p><img src=\"https://img.serverlesscloud.cn/2020326/1585233251397-%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_15852332173310.png\"></p>\n<h3 id=\"3、serverless场景典型的工作流程\"><a href=\"#3%E3%80%81serverless%E5%9C%BA%E6%99%AF%E5%85%B8%E5%9E%8B%E7%9A%84%E5%B7%A5%E4%BD%9C%E6%B5%81%E7%A8%8B\" aria-label=\"3、serverless场景典型的工作流程 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><strong>3、Serverless场景典型的工作流程</strong></h3>\n<p>它有涉及到这个概念，第一个概念是事件状态，表示允许等待来自事件源的一个事件。第二个是操作/任务状态，表示这个状态下允许按照顺序或者并行运行一个函数。第三个是切换状态，它允许切换到多个其他状态，比方说前一个函数的结果，然后触发分支，转换到不同的一个状态。第四个是停止状态，用来终止工作流程。</p>\n<p>然后让我们看一下工作流程，他其实是通过我们的一个事件触发，然后判断事件状态，通过事件状态调用函数。从函数A中拿到结果，然后再到切换状态，完成后可能会有两个结果，结果2、结果3，这是\nFunction 的结果，其实是调取的 Function\n的前一个函数的事件或者是前一个函数的数值，然后再去做操作任务，最后来到\nFunctionB 或者\nFunctionC，这个流程就结束了。这是我们典型的事件状态，包括函数调用的一个工作流程。</p>\n<p><img src=\"https://img.serverlesscloud.cn/2020326/1585233251430-%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_15852332173310.png\" alt=\"Python\"></p>\n<h3 id=\"4、serverless-函数架构规范\"><a href=\"#4%E3%80%81serverless-%E5%87%BD%E6%95%B0%E6%9E%B6%E6%9E%84%E8%A7%84%E8%8C%83\" aria-label=\"4、serverless 函数架构规范 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><strong>4、Serverless 函数架构规范</strong></h3>\n<p>现在我们来看一下 Serverless 的底层的 FaaS\n函数、调用模型如何定义，包括约束。</p>\n<p>首先看函数定义，下图表示比较清楚。函数定义是包括几个概念，第一个概念是\nID，这很好理解，名称、标签、版本\nID，其实刚刚所讲的运行时，也是函数定义里面的；还有函数处理的一个程序，就是函数所拿到的事件去做一些处理；以及里面所包括的代码，还有包括依赖，比方说我们今天所有有英文的实践，可能就需要去用依赖，然后统一上传到函数，以及环境变量。</p>\n<p>元数据详情，有几个概念，第一个是版本的概念，第二个是环境变量，第三个是执行角色，第四个是资源，第五个是超时，其实元数据详情这里面的一些都是最基础、可能最常用的一些数据详情的结构。</p>\n<p>第三点数据绑定，其实是一些无服务器框架允许用户去指定函数使用的输入输出的一些数据资源。这样就可以让开发人员去帮助函数资源的简化，来提高性能来获取更好的安全性，当然作为开发者来讲，并不是很关键。</p>\n<p>函数约束，是代表运行Serverless函数时满足的通用的条件，比方说我们的函数必须与不同的事件类的底层来实现分离，是很基础的一些东西，包括每次调用的方法，不需要不同的函数，就意思说，我们的函数其实它是可复用的，以及事件源是可以去调用多个函数，这些是函数的约束，还有包括它的特性。</p>\n<p>函数调用类型，函数调用分四种，第一种是同步请求，第二种是异步请求，第三种是信息流，或者叫记录流，第四种是批量作业。</p>\n<p>同步请求很好理解，就比方APP请求，GIPC的调用，它代表客户端发出的一个请求等待并立即响应，包括我们这次的实践，所用的方式也就是同步请求。</p>\n<p>异步请求，异步请求就有很多，就比方说在SF上看到的触发、MQTT的触发、电子邮件，还有cos更改的命令触发，以及计划事件，比方说用我们的时间触发器，去写一个时间，自动触发任务，这都叫异步消息队列请求。</p>\n<p><img src=\"https://img.serverlesscloud.cn/2020326/1585233251502-%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_15852332173310.png\" alt=\"Python\"></p>\n<h2 id=\"二、serverless-的事件与规范\"><a href=\"#%E4%BA%8C%E3%80%81serverless-%E7%9A%84%E4%BA%8B%E4%BB%B6%E4%B8%8E%E8%A7%84%E8%8C%83\" aria-label=\"二、serverless 的事件与规范 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>二、Serverless 的事件与规范</h2>\n<p>什么是 Severless\n的事件，然后是怎么去定义的，我觉得这是所需要知道的一个重点。</p>\n<h3 id=\"1、什么是-cloudevents？\"><a href=\"#1%E3%80%81%E4%BB%80%E4%B9%88%E6%98%AF-cloudevents%EF%BC%9F\" aria-label=\"1、什么是 cloudevents？ 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><strong>1、什么是 CloudEvents？</strong></h3>\n<p>CloudEvents 是一个规范，它是由先 CSF\n提出的规范，主要是以通用的格式来描述事件数据以提供跨服务、跨平台、跨系统的交互能力，我们可以去\nCloudEvents 的 GitHub 主页去看关于 FaaS\n的详的事件，包括事件规范。比较重要的一点就是他的所有实现都必须要支持\nJSON 格式，这也是 FaaS 和其他不太相同的一个地方。</p>\n<h3 id=\"2、什么是事件？\"><a href=\"#2%E3%80%81%E4%BB%80%E4%B9%88%E6%98%AF%E4%BA%8B%E4%BB%B6%EF%BC%9F\" 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><strong>2、什么是事件？</strong></h3>\n<p>事件其实无处不在，每个事件源所产生的事件都各不相同，所以这对于开发者来说需要不断的去重复学习如何消费不同类型的事件。就比方说可能腾讯云\nCMQ 产生的事件，还有 API\n网关的产生的事件或其他厂商的事件，是不太一样的，就可能一些入参、出参值都是不太一样的。</p>\n<p>不同厂商的 API 网关的触发器，它所产生的事件也可能不是很相同的，这可以在\nSLF\n里面去验证一下，我也给到腾讯云的事件的一些基础参考。但是事件是基于触发，触发器达到某项特定事件之后，去入参给\nFaaS 层，云函数去做一些操作。</p>\n<h3 id=\"3、必须的事件属性。\"><a href=\"#3%E3%80%81%E5%BF%85%E9%A1%BB%E7%9A%84%E4%BA%8B%E4%BB%B6%E5%B1%9E%E6%80%A7%E3%80%82\" 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><strong>3、必须的事件属性。</strong></h3>\n<p>这其实也是\nSCF 的一个统一的管理委员会去制定的一个必须的事件属性，比方说第一个很简单，就是\nID，所有的事件都是需要有个 ID\n来帮助我们进行事件的查询，还有包括事件的一些处理，以及识别事件所发生的上下文，这块很简单，就是入参和传参。</p>\n<p>还包括事件所使用的该版本的 CloudEvents\n的规范，这块可以去腾讯云官网参考一下这块的一些属性。以及发生相关事件的类型值，还有\nData 的数据内容格式，以及事件上下文主题，发生事件的时间节点。</p>\n<p>我还想在这里为家补充的几个点就是事件也是有分类的，大致可以分为几类：</p>\n<ul>\n<li>第一类，是事件、消息服务，这块内容就很多，比方说 MPL、MQTT。</li>\n<li>第二类是存储服务，很简单，就比方说 COS。</li>\n<li>第三类是端点服务，比方说物联网、ATP 网关、移动设备。</li>\n<li>第四类是配置数据库，比方说地图就是一种配置数据库。</li>\n<li>第五类是使用特定语言去做的一些 SDK 的用户程序，这也算作事件源。</li>\n<li>第六类是计划事件，可以具象的说计划事件其实就是定制触发，就是定期去启用函数的一个功能。</li>\n</ul>\n<p>虽然我们每个事件所提供的数据，其实在不同事件源之间都是有不同的，但事件的结构应该是通用的，所以我们能够分装关于事件的一些特定的信息。</p>\n<h2 id=\"三、serverless工程化的难点与挑战\"><a href=\"#%E4%B8%89%E3%80%81serverless%E5%B7%A5%E7%A8%8B%E5%8C%96%E7%9A%84%E9%9A%BE%E7%82%B9%E4%B8%8E%E6%8C%91%E6%88%98\" aria-label=\"三、serverless工程化的难点与挑战 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><strong>三、Serverless工程化的难点与挑战</strong></h2>\n<p>说到Serverless工程化的难点、挑战，这块我其实都没怎么写，就直接在百度上一搜，这东西其实大家都可以搜到的，所以我也不给大家多讲，我需要讲的是面对Serverless工程化的难点，我们需要做什么以及怎么去做，或者是有没有什么工具或者方式，去攻克这些难点。</p>\n<p><img src=\"https://img.serverlesscloud.cn/2020326/1585233251437-%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_15852332173310.png\" alt=\"Python\"></p>\n<h3 id=\"第一点：长时间问题\"><a href=\"#%E7%AC%AC%E4%B8%80%E7%82%B9%EF%BC%9A%E9%95%BF%E6%97%B6%E9%97%B4%E9%97%AE%E9%A2%98\" 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><strong>第一点：长时间问题</strong></h3>\n<p>在FaaS层，因为它就是通过事件触发，或者是有一个运行时的概念或者是用完即走的概念，所以说不太适合在长时间去运行应用。这其实是不可否认的，但是我们有一个方案，是ServerlessFramework下的一个component，我们其实是有一定的方案去解决长时间运行运用的难点，但怎么说我还是不建议大家用FaaS去做长时间，这是我的非常固执的一个观点，但我们是有解决方案的。</p>\n<p><img src=\"https://img.serverlesscloud.cn/2020326/1585233251474-%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_15852332173310.png\" alt=\"Python\"></p>\n<h3 id=\"第二点：完全依赖于第三方服务\"><a href=\"#%E7%AC%AC%E4%BA%8C%E7%82%B9%EF%BC%9A%E5%AE%8C%E5%85%A8%E4%BE%9D%E8%B5%96%E4%BA%8E%E7%AC%AC%E4%B8%89%E6%96%B9%E6%9C%8D%E5%8A%A1\" 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><strong>第二点：完全依赖于第三方服务</strong></h3>\n<p>其实说到底我们 Serverless\n其实就是免运维，所以说依赖于升第三方服务的时候，第三方是可以提供我们一站式的解决方案。</p>\n<p><img src=\"https://img.serverlesscloud.cn/2020326/1585233251532-%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_15852332173310.png\" alt=\"Python\"></p>\n<p>意思就是说，我觉得依赖于第三方其实是一件好事，因为它可以帮助我们去做一些监控、负载均衡、业务集群，最关键的是弹性的扩缩容，并且可以帮助我们免运维，所以我觉得完全依赖于第三方，其实这不应该是他的一个缺点，应该算作一个优势，尤其在云原生的时代，他其实是我们的一个优势。</p>\n<h3 id=\"第三点：冷启动的时间\"><a href=\"#%E7%AC%AC%E4%B8%89%E7%82%B9%EF%BC%9A%E5%86%B7%E5%90%AF%E5%8A%A8%E7%9A%84%E6%97%B6%E9%97%B4\" 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><strong>第三点：冷启动的时间</strong></h3>\n<p>因为我们的函数在你运行的时候，才会启动，所以说不是你启完之后一直都是在线的，Serverless是只有你在运行就是有事件触发的时候，才会去调用函数，去做计算的运行，导致一个冷启动时间会特别长。</p>\n<p>但这块其实我做了一个测试，这个其实是有关于云厂商的优化的建议，我测了腾讯云还有包括国内的A厂商、B厂商，其实在我的测试中会发现，其实腾讯云的耗时是最短的，我可以给大家共享出这块测试的代码，然后大家可以自己去在同区域，同网络环境，同配置下去跑冷启动的时间，其实腾讯云在其他厂商中相比来说，它的冷启动时间最短。</p>\n<p><img src=\"https://img.serverlesscloud.cn/2020326/1585233251697-%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_15852332173310.png\" alt=\"Python\"></p>\n<p>其次冷启动时间有什么解决方案，基本解决方案主要就两大块。</p>\n<ul>\n<li>第一块就是复用，可以使用容器的一些复用技术。</li>\n<li>第二块是预热，可以去做一些预创建，热门代码的缓存、网络优化，预启动来做一些预热解决冷启动</li>\n</ul>\n<p>这块的话我其实还是建议大家就是不要过分关于论启动的基本方案，因为基本方案其实是云厂商一直在做的一些优化点。所以说大家尽量不要去纠结于这种特别底层的技术实现。</p>\n<p><img src=\"https://img.serverlesscloud.cn/2020326/1585233251675-%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_15852332173310.png\" alt=\"Python\"></p>\n<h3 id=\"第四点：缺乏调试和开发工具\"><a href=\"#%E7%AC%AC%E5%9B%9B%E7%82%B9%EF%BC%9A%E7%BC%BA%E4%B9%8F%E8%B0%83%E8%AF%95%E5%92%8C%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7\" 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><strong>第四点：缺乏调试和开发工具</strong></h3>\n<p>其实我们最近出了一个特别好用的工具，推出了 Serverless Framework\n是可以贯穿到我们整体的 Serverless\n应用的生命周期，有包括我们非常健全的开发部署环节的。</p>\n<p>测试环节的测试监控，还包括安全环节的，以及 debug\n的时候所用到的一些的debug方案，还有包括一些具体的的debug的一个解决实现，还有包括详细的Dashboard，最后还包括审计、操作记录、告警信息、团队协作。</p>\n<p><img src=\"https://img.serverlesscloud.cn/2020326/1585233251760-%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_15852332173310.png\" alt=\"Python\"></p>\n<p>他其实是贯穿了整体的Serverless的一个整合应用生命周期，所以这块的调试工具，还有开发工具其实是很好解决的事情。</p>\n<h3 id=\"第五点：语言版本的落后\"><a href=\"#%E7%AC%AC%E4%BA%94%E7%82%B9%EF%BC%9A%E8%AF%AD%E8%A8%80%E7%89%88%E6%9C%AC%E7%9A%84%E8%90%BD%E5%90%8E\" 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><strong>第五点：语言版本的落后</strong></h3>\n<p>反正我是可以看到基本上主流的版本，比方说\nPython2.7、Python3.6，还有Node.js8.9，包括 PHP\n这些常用的新的稳定的原版本，其实都是有在支持我们的 runtime。</p>\n<p>当然这块的话，有的同学可能就会问到一个点，就是很尴尬一点，比方说你Python虽然\n3.6 但现在 Python 都已经到\n3.8，你为什么不用？这个我的观点就是并不是所有语言的语言版本越高越好，我觉得这点还是需要去寻求一个稳定，意思就是说我们需要去找到一个长期维护，并且稳定的版本，然后再给大家去用。</p>\n<p>我举个比较简单的例子，就是PHP7.0的时候出了N多个bug，可能达到了7.1\\7.2之后，这些东西才渐渐地稳定下来，这些新特性才有人去用,我是这么看待语言版本落后的问题。</p>\n<p><img src=\"https://img.serverlesscloud.cn/2020326/1585233251775-%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_15852332173310.png\" alt=\"Python\"></p>\n<p>然后我们来看一下有哪些人在用 Serverless\n的架构，就如下图所示，基本上现有的主流的一些互联网公司，它其实都是在有用\nServerless 架构，其实Serverless\n架构也是势在必行。所以我觉得开发者一定是要懂得并且学习Serverless的架构才能在我们的行业中有一定的竞争力，我是保持我这个观点的。</p>\n<p>最后就是 Serverless 的架构应用。我们现在和 Framework 推出了很多的\nComponent，你也可以成为我们开源社区的贡献者，可以去直接去搜Serverless\n官方网站，在最底下订阅我们的公众号，假如你有问题的话也可以将问题提交给小助手，我们会有专门的一些工作人员为大家去做一些更多详细的解答。</p>\n<p><img src=\"https://img.serverlesscloud.cn/2020326/1585233251963-%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_15852332173310.png\" alt=\"Python\"></p>\n<h2 id=\"实战：pythonserverless-开发情人节表白页\"><a href=\"#%E5%AE%9E%E6%88%98%EF%BC%9Apythonserverless-%E5%BC%80%E5%8F%91%E6%83%85%E4%BA%BA%E8%8A%82%E8%A1%A8%E7%99%BD%E9%A1%B5\" aria-label=\"实战：pythonserverless 开发情人节表白页 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><strong>实战：Python+Serverless 开发情人节表白页</strong></h2>\n<p>然后那么最后我们来去看一下 Python+Serverless 怎么去开发情人节表白页。</p>\n<h3 id=\"1-安装\"><a href=\"#1-%E5%AE%89%E8%A3%85\" 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<ul>\n<li>通过 npm 安装 serverless</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$ npm install -g serverless</code></pre></div>\n<h3 id=\"2-创建\"><a href=\"#2-%E5%88%9B%E5%BB%BA\" 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<ul>\n<li>本地创建 serverless.yml 文件：</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$ touch serverless.yml</code></pre></div>\n<ul>\n<li>初始化一个新的 npm 包，并安装 Express：</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npm init              # 创建后持续回车npm i --save express  # 安装express</code></pre></div>\n<ul>\n<li>创建一个 <code class=\"language-text\">app.js</code>文件，并在其中创建您的\nExpress App：</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const express = require(&#39;express&#39;)const app = express()app.get(&#39;/&#39;, function(req, res) {  res.send(&#39;Hello Express&#39;)})// don&#39;t forget to export!module.exports = app</code></pre></div>\n<h3 id=\"3-配置\"><a href=\"#3-%E9%85%8D%E7%BD%AE\" 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<ul>\n<li>在 serverless.yml 中进行如下配置</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"># serverless.ymlexpress:  component: &#39;@serverless/tencent-express&#39;  inputs:    region: ap-shanghai</code></pre></div>\n<h3 id=\"4-部署\"><a href=\"#4-%E9%83%A8%E7%BD%B2\" aria-label=\"4 部署 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>4. 部署</h3>\n<ul>\n<li>通过<code class=\"language-text\">sls</code>命令进行部署，并可以添加<code class=\"language-text\">--debug</code>参数查看部署过程中的信息</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$ sls --debug  DEBUG ─ Resolving the template&#39;s static variables.  DEBUG ─ Collecting components from the template.  DEBUG ─ Downloading any NPM components found in the template.  DEBUG ─ Analyzing the template&#39;s components dependencies.  DEBUG ─ Creating the template&#39;s components graph.  DEBUG ─ Syncing template state.  DEBUG ─ Executing the template&#39;s components graph.  DEBUG ─ Compressing function ExpressComponent_7xRrrd file to /Users/dfounderliu/Desktop/temp/code/.serverless/ExpressComponent_7xRrrd.zip.  DEBUG ─ Compressed function ExpressComponent_7xRrrd file successful  DEBUG ─ Uploading service package to cos[sls-cloudfunction-ap-shanghai-code]. sls-cloudfunction-default-ExpressComponent_7xRrrd-1572512568.zip  DEBUG ─ Uploaded package successful /Users/dfounderliu/Desktop/temp/code/.serverless/ExpressComponent_7xRrrd.zip  DEBUG ─ Creating function ExpressComponent_7xRrrd  DEBUG ─ Created function ExpressComponent_7xRrrd successful  DEBUG ─ Starting API-Gateway deployment with name express.TencentApiGateway in the ap-shanghai region  DEBUG ─ Using last time deploy service id service-n0vs2ohb  DEBUG ─ Updating service with serviceId service-n0vs2ohb.  DEBUG ─ Endpoint ANY / already exists with id api-9z60urs4.  DEBUG ─ Updating api with api id api-9z60urs4.  DEBUG ─ Service with id api-9z60urs4 updated.  DEBUG ─ Deploying service with id service-n0vs2ohb.  DEBUG ─ Deployment successful for the api named express.TencentApiGateway in the ap-shanghai region.  express:    region:              ap-shanghai    functionName:        ExpressComponent_7xRrrd    apiGatewayServiceId: service-n0vs2ohb    url:                 http://service-n0vs2ohb-1300415943.ap-shanghai.apigateway.myqcloud.com/release/  36s › express › done</code></pre></div>\n<p>部署完毕后，可以在浏览器中访问返回的链接，看到对应的express返回值。</p>\n<p>实践相关源码：<a href=\"https://docs.qq.com/doc/DVURnWFp3SFNGd3N\">https://docs.qq.com/doc/DVURnWFp3SFNGd3N</a></p>\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>\n<p><a href=\"/blog/2020-03-16-serverlesspython/#%E4%B8%80%E3%80%81serverless-%E7%9A%84%E6%9E%B6%E6%9E%84%E8%A7%84%E8%8C%83\">一、Serverless 的架构规范</a></p>\n<ul>\n<li><a href=\"/blog/2020-03-16-serverlesspython/#1%E3%80%81serverless-web-%E5%9C%BA%E6%99%AF%E5%A4%84%E7%90%86%E7%9A%84%E5%85%B8%E5%9E%8B%E7%BB%93%E6%9E%84\">1、Serverless Web 场景处理的典型结构</a></li>\n<li><a href=\"/blog/2020-03-16-serverlesspython/#2%E3%80%81serverless%E5%A4%84%E7%90%86%E6%A8%A1%E5%9E%8B\">2、Serverless处理模型</a></li>\n<li><a href=\"/blog/2020-03-16-serverlesspython/#3%E3%80%81serverless%E5%9C%BA%E6%99%AF%E5%85%B8%E5%9E%8B%E7%9A%84%E5%B7%A5%E4%BD%9C%E6%B5%81%E7%A8%8B\">3、Serverless场景典型的工作流程</a></li>\n<li><a href=\"/blog/2020-03-16-serverlesspython/#4%E3%80%81serverless-%E5%87%BD%E6%95%B0%E6%9E%B6%E6%9E%84%E8%A7%84%E8%8C%83\">4、Serverless 函数架构规范</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"/blog/2020-03-16-serverlesspython/#%E4%BA%8C%E3%80%81serverless-%E7%9A%84%E4%BA%8B%E4%BB%B6%E4%B8%8E%E8%A7%84%E8%8C%83\">二、Serverless 的事件与规范</a></p>\n<ul>\n<li><a href=\"/blog/2020-03-16-serverlesspython/#1%E3%80%81%E4%BB%80%E4%B9%88%E6%98%AF-cloudevents%EF%BC%9F\">1、什么是 CloudEvents？</a></li>\n<li><a href=\"/blog/2020-03-16-serverlesspython/#2%E3%80%81%E4%BB%80%E4%B9%88%E6%98%AF%E4%BA%8B%E4%BB%B6%EF%BC%9F\">2、什么是事件？</a></li>\n<li><a href=\"/blog/2020-03-16-serverlesspython/#3%E3%80%81%E5%BF%85%E9%A1%BB%E7%9A%84%E4%BA%8B%E4%BB%B6%E5%B1%9E%E6%80%A7%E3%80%82\">3、必须的事件属性。</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"/blog/2020-03-16-serverlesspython/#%E4%B8%89%E3%80%81serverless%E5%B7%A5%E7%A8%8B%E5%8C%96%E7%9A%84%E9%9A%BE%E7%82%B9%E4%B8%8E%E6%8C%91%E6%88%98\">三、Serverless工程化的难点与挑战</a></p>\n<ul>\n<li><a href=\"/blog/2020-03-16-serverlesspython/#%E7%AC%AC%E4%B8%80%E7%82%B9%EF%BC%9A%E9%95%BF%E6%97%B6%E9%97%B4%E9%97%AE%E9%A2%98\">第一点：长时间问题</a></li>\n<li><a href=\"/blog/2020-03-16-serverlesspython/#%E7%AC%AC%E4%BA%8C%E7%82%B9%EF%BC%9A%E5%AE%8C%E5%85%A8%E4%BE%9D%E8%B5%96%E4%BA%8E%E7%AC%AC%E4%B8%89%E6%96%B9%E6%9C%8D%E5%8A%A1\">第二点：完全依赖于第三方服务</a></li>\n<li><a href=\"/blog/2020-03-16-serverlesspython/#%E7%AC%AC%E4%B8%89%E7%82%B9%EF%BC%9A%E5%86%B7%E5%90%AF%E5%8A%A8%E7%9A%84%E6%97%B6%E9%97%B4\">第三点：冷启动的时间</a></li>\n<li><a href=\"/blog/2020-03-16-serverlesspython/#%E7%AC%AC%E5%9B%9B%E7%82%B9%EF%BC%9A%E7%BC%BA%E4%B9%8F%E8%B0%83%E8%AF%95%E5%92%8C%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7\">第四点：缺乏调试和开发工具</a></li>\n<li><a href=\"/blog/2020-03-16-serverlesspython/#%E7%AC%AC%E4%BA%94%E7%82%B9%EF%BC%9A%E8%AF%AD%E8%A8%80%E7%89%88%E6%9C%AC%E7%9A%84%E8%90%BD%E5%90%8E\">第五点：语言版本的落后</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"/blog/2020-03-16-serverlesspython/#%E5%AE%9E%E6%88%98%EF%BC%9Apythonserverless-%E5%BC%80%E5%8F%91%E6%83%85%E4%BA%BA%E8%8A%82%E8%A1%A8%E7%99%BD%E9%A1%B5\">实战：Python+Serverless 开发情人节表白页</a></p>\n<ul>\n<li><a href=\"/blog/2020-03-16-serverlesspython/#1-%E5%AE%89%E8%A3%85\">1. 安装</a></li>\n<li><a href=\"/blog/2020-03-16-serverlesspython/#2-%E5%88%9B%E5%BB%BA\">2. 创建</a></li>\n<li><a href=\"/blog/2020-03-16-serverlesspython/#3-%E9%85%8D%E7%BD%AE\">3. 配置</a></li>\n<li><a href=\"/blog/2020-03-16-serverlesspython/#4-%E9%83%A8%E7%BD%B2\">4. 部署</a></li>\n</ul>\n</li>\n</ul>"},"previousBlog":{"id":"0529eafa-9029-59ad-875f-0b20e3a0c315","frontmatter":{"thumbnail":"https://img.serverlesscloud.cn/2020326/1585231022072-%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_15852308195522.png","authors":["Adrian S."],"categories":["guides-and-tutorials"],"date":"2020-03-17T00:00:00.000Z","title":"看懂 Serverless SSR，这一篇就够了！","description":"了解我们如何为每个 Webiny 网站获得出色的 SEO 支持，以及如何在无服务器环境中使用 SSR 使其超快运行","authorslink":["https://blog.webiny.com/serverless-side-rendering-e1c0924b8da1"],"translators":null,"translatorslink":null,"tags":["Serverless SSR","AWS Lambda"],"keywords":"腾讯云 Serverless,Serverless,Serverless framework","outdated":null},"wordCount":{"words":2153,"sentences":218,"paragraphs":215},"fileAbsolutePath":"/opt/build/repo/content/blog/2020-03-17-serverless-ssr.md","fields":{"slug":"/blog/2020-03-17-serverless-ssr/","keywords":["go","nodejs","react","serverless","ssr","单页应用","服务端渲染","服务器端渲染","客户端渲染","同构渲染","无服务器","页面","缓存","渲染","Lambda","应用程序","方法","服务器"]}},"nextBlog":{"id":"c18924ec-cade-5f2f-91ca-e1717924521b","frontmatter":{"thumbnail":"https://img.serverlesscloud.cn/2020115/1579078112543-1577769064015-joshua-aragon-FGXqbqbGt5o-unsplash.jpg","authors":["Aceyclee"],"categories":["engineering-culture","user-stories"],"date":"2020-03-14T00:00:00.000Z","title":"前端为什么要关注 Serverless?","description":"前端为什么要接 serverless? 交给后端不行吗?","authorslink":["https://www.zhihu.com/people/Aceyclee"],"translators":null,"translatorslink":null,"tags":["Serverless","全栈应用"],"keywords":"serverless发展,Serverless 基本概念,Serverless生产力","outdated":null},"wordCount":{"words":233,"sentences":51,"paragraphs":51},"fileAbsolutePath":"/opt/build/repo/content/blog/2020-03-14-why-fe-learn-sls.md","fields":{"slug":"/blog/2020-03-14-why-fe-learn-sls/","keywords":["serverless","vue","vuejs","website","website 组件","serverless","Serverless","tencent","express","serverlesscloud","github"]}},"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":"36ad18b2-1694-5b48-bb23-d6a5575343cd","frontmatter":{"thumbnail":"https://main.qcloudimg.com/raw/4c101fcf0be63a70e0aa992da17dd955.png","authors":["BrianNeisler"],"categories":["engineering-culture"],"date":"2018-01-24T00:00:00.000Z","title":"如何将设计思维应用到精益初创公司的软件开发中","description":"关于将设计思维与敏捷开发相结合的尝试 —— 成功与失败剖析","authorslink":["https://serverless.com/author/brianneisler/"],"translators":["Aceyclee"],"translatorslink":["https://www.zhihu.com/people/Aceyclee"],"tags":["敏捷开发","Serverless"],"keywords":"Serverless 设计思维,Serverless 敏捷开发","outdated":null},"wordCount":{"words":213,"sentences":41,"paragraphs":41},"fileAbsolutePath":"/opt/build/repo/content/blog/2018-01-23-appy-design-thinking-lean-startup-software-development.md","fields":{"slug":"/blog/2018-01-23-appy-design-thinking-lean-startup-software-development/","keywords":["思维","设计","用户","团队","产品","想法","验证","优先级","敏捷","公司"]}}},{"node":{"id":"e7fe6284-d107-5e80-8e6e-cae075aff38c","frontmatter":{"thumbnail":"https://main.qcloudimg.com/raw/67b0bff4886896e1ee5d4f5917cf6096.jpg","authors":["FelixDesroches"],"categories":["engineering-culture"],"date":"2018-02-09T00:00:00.000Z","title":"Serverless 公司的远程团队沟通策略","description":"Serverless 团队分散在全球各地，本文介绍我们如何管理沟通策略和远程协作。","authorslink":["https://serverless.com/author/felixdesroches/"],"translators":["Aceyclee"],"translatorslink":["https://www.zhihu.com/people/Aceyclee"],"tags":["远程协同","Serverless"],"keywords":"Serverless 远程团队,Serverless 沟通策略,Serverless 远程协作","outdated":null},"wordCount":{"words":137,"sentences":22,"paragraphs":22},"fileAbsolutePath":"/opt/build/repo/content/blog/2018-02-09-communication-strategies-remote-teams.md","fields":{"slug":"/blog/2018-02-09-communication-strategies-remote-teams/","keywords":["沟通","团队","工具","Radical","Candor","团建","Slack","方式"]}}},{"node":{"id":"548b1bba-ea90-5753-a0eb-040193083655","frontmatter":{"thumbnail":"https://img.serverlesscloud.cn/20191212/1576149285117-charmmie-square.jpg","authors":["CharmmieHendon"],"categories":["engineering-culture"],"date":"2018-02-01T00:00:00.000Z","title":"一名时尚艺术家转行到科技行业的历程","description":"Serverless 团队新成员 Charmmie 是从高级时装行业转行到技术领域的，本文是她的故事，太酷了。","authorslink":["https://serverless.com/author/charmmiehendon/"],"translators":["Aceyclee"],"translatorslink":["https://www.zhihu.com/people/Aceyclee"],"tags":["Serverless"],"keywords":"Serverless 团队成员,Charmmie","outdated":null},"wordCount":{"words":242,"sentences":39,"paragraphs":37},"fileAbsolutePath":"/opt/build/repo/content/blog/2018-01-30-serverless-style-from-fashion-to-tech.md","fields":{"slug":"/blog/2018-01-30-serverless-style-from-fashion-to-tech/","keywords":["go","serverless","Serverless","技术","科技","Sam","行业","时尚","工作","时装","旧金山","适合"]}}},{"node":{"id":"dc9c5f49-4ee1-56bb-b5ec-6780d9fd69e1","frontmatter":{"thumbnail":"https://main.qcloudimg.com/raw/c2598ce0fad913a7d1fe2bfcdd3324e3.jpeg","authors":["NickGottlieb"],"categories":["engineering-culture"],"date":"2018-02-23T00:00:00.000Z","title":"通过 Serverless 架构构建更好的软件","description":"Nick Gottlieb 分享了他在 ServerlessConf Tokyo 上关于 Serverless、软件状态以及提高生产效率方法的演讲。","authorslink":["https://serverless.com/author/nickgottlieb/"],"translators":["Aceyclee"],"translatorslink":["https://www.zhihu.com/people/Aceyclee"],"tags":["Serverless"],"keywords":"Serverless 架构构建,ServerlessConf Tokyo,Serverless 效率方法","outdated":null},"wordCount":{"words":200,"sentences":42,"paragraphs":42},"fileAbsolutePath":"/opt/build/repo/content/blog/2018-02-23-serverless-path-building-better-software.md","fields":{"slug":"/blog/2018-02-23-serverless-path-building-better-software/","keywords":["无服务器","云函数","Serverless","服务","构建","工具","软件","开发人员","函数","架构"]}}},{"node":{"id":"73576d26-e0ce-5f26-9330-64b4f3889157","frontmatter":{"thumbnail":"https://main.qcloudimg.com/raw/3cb7b20955d78ced738e0279bb3f6f41.jpg","authors":["AndreaPasswater"],"categories":["news","engineering-culture"],"date":"2018-03-09T00:00:00.000Z","title":"Serverless 数据解读：2018 报告","description":"Serverless Framework 使用统计数据：事件源、服务结构、运行时长等等。","authorslink":["https://serverless.com/author/andreapasswater/"],"translators":["Aceyclee"],"translatorslink":["https://www.zhihu.com/people/Aceyclee"],"tags":["事件源","服务结构"],"keywords":"Serverless 统计数据,Serverless 事件源,Serverless 服务结构","outdated":null},"wordCount":{"words":212,"sentences":45,"paragraphs":45},"fileAbsolutePath":"/opt/build/repo/content/blog/2018-03-09-serverless-by-the-numbers-2018-data-report.md","fields":{"slug":"/blog/2018-03-09-serverless-by-the-numbers-2018-data-report/","keywords":["go","serverless","无服务器","云函数","服务","使用率","Go","部署"]}}},{"node":{"id":"665f9ce2-4451-59fd-bf98-1861789d3b3b","frontmatter":{"thumbnail":"https://s3-us-west-2.amazonaws.com/assets.blog.serverless.com/Serverless_logo.png","authors":["AndreaPasswater"],"categories":["guides-and-tutorials","engineering-culture"],"date":"2018-03-19T00:00:00.000Z","title":"如何为无服务器开放源代码项目做贡献","description":"想要为无服务器开放源代码项目做贡献？您可以遵循下面的指南。","authorslink":null,"translators":null,"translatorslink":null,"tags":null,"keywords":null,"outdated":null},"wordCount":{"words":96,"sentences":36,"paragraphs":36},"fileAbsolutePath":"/opt/build/repo/content/blog/2018-03-19-how-contribute-to-serverless-open-source.md","fields":{"slug":"/blog/2018-03-19-how-contribute-to-serverless-open-source/","keywords":["serverless","无服务器","serverless","github","插件","服务器","贡献","示例","blog","contribute"]}}},{"node":{"id":"a3e92579-65c3-5159-937c-32d18c5df7d7","frontmatter":{"thumbnail":"https://s3-us-west-2.amazonaws.com/assets.blog.serverless.com/why-not/why-not-header.png","authors":["AndreaPasswater"],"categories":["guides-and-tutorials","operations-and-observability","engineering-culture"],"date":"2018-03-21T00:00:00.000Z","title":"不适合选择无服务器的情境及原因","description":"无服务器既有优点也有缺点。那么，哪些情境下不适合选择无服务器？原因又是什么呢？","authorslink":null,"translators":null,"translatorslink":null,"tags":null,"keywords":null,"outdated":null},"wordCount":{"words":163,"sentences":43,"paragraphs":43},"fileAbsolutePath":"/opt/build/repo/content/blog/2018-03-21-when-why-not-use-serverless.md","fields":{"slug":"/blog/2018-03-21-when-why-not-use-serverless/","keywords":["faas","react","serverless","spa","无服务器","无服务器函数","无服务器架构","无服务器开发","服务器","twitter","serverless","blockquote","lang","script","en"]}}}],"totalCount":87}},"pageContext":{"isCreatedByStatefulCreatePages":false,"blogId":"59a44895-3215-5ad0-8f99-9da7ee04ecdd","previousBlogId":"0529eafa-9029-59ad-875f-0b20e3a0c315","nextBlogId":"c18924ec-cade-5f2f-91ca-e1717924521b","categories":["user-stories","engineering-culture"]}}}