{"componentChunkName":"component---src-templates-best-practice-detail-tsx","path":"/best-practice/2020-07-16-registry-mapreduce","result":{"data":{"currentBlog":{"id":"ca884fd4-891f-599b-ac9f-b6f1169df802","frontmatter":{"thumbnail":"https://img.serverlesscloud.cn/2020720/1595246883106-%E5%B0%81%E9%9D%A2%E5%9B%BE.jpg","authors":["杜佳辰"],"categories":["best-practice"],"date":"2020-07-16T00:00:00.000Z","title":"通过 Serverless Regsitry 快速开发与部署一个 WordCount 实例","description":"本文介绍了如何通过 Registry 开发与部署一个项目模版","authorslink":["https://github.com/Jiachen0417"],"translators":null,"translatorslink":null,"tags":["Registry","MapReduce"],"keywords":"Serverless Registry,MapReduce","outdated":null},"wordCount":{"words":182,"sentences":46,"paragraphs":46},"fileAbsolutePath":"/opt/build/repo/content/best-practice/2020-07-16-registry-mapreduce.md","fields":{"slug":"/best-practice/2020-07-16-registry-mapreduce/","keywords":["serverless","spa","云函数","serverless","cos","模版","MapReduce","yml","srcmr"]},"html":"<p>在学习 MapReduce 的过程中，不少人接触的第一个项目就是单词计数。单词计数通过两个函数 Map 和 Reduce，可以快速地统计出文本文件中每个单词出现的个数，它虽然简单，但也是最能体现 MapReduce 思想的程序之一。而 Serverless 的出现，为 MapReduce 进行大数据处理又提供了一个新的部署方案，Serverless 与 MapReduce 究竟如何结合呢？</p>\n<p>本文将通过一个简单的教程，指导大家快速开发一个基于 MapReduce 的 WordCount 应用模版，并在 Serverless 应用中心 Registry 里实现复用。</p>\n<h2 id=\"前提条件\"><a href=\"#%E5%89%8D%E6%8F%90%E6%9D%A1%E4%BB%B6\" 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>已安装 <strong>Serverless Framework</strong>，并保证您的 Serverless Framework 不低于以下版本：</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"65349458947963760000\"\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(`\\$ serverless –v\nFramework Core: 1.74.1 (standalone)\nPlugin: 3.6.14\nSDK: 2.3.1\nComponents: 2.31.6`, `65349458947963760000`)\"\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=\"console\"><pre class=\"language-console\"><code class=\"language-console\">$ serverless –v\nFramework Core: 1.74.1 (standalone)\nPlugin: 3.6.14\nSDK: 2.3.1\nComponents: 2.31.6</code></pre></div>\n<h2 id=\"实现概要\"><a href=\"#%E5%AE%9E%E7%8E%B0%E6%A6%82%E8%A6%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<p>下面是该实例的实现流程：</p>\n<ul>\n<li>创建函数与 COS Bucket。</li>\n<li>用户将对象上传到 COS 中的源存储桶（对象创建事件）。</li>\n<li>COS Bucket检测到对象创建事件。</li>\n<li>COS 调用函数并将事件数据作为参数传递给函数，由此将 <code class=\"language-text\">cos:ObjectCreated:*</code> 事件发布给函数。</li>\n<li>SCF 平台接收到调用请求，执行函数。</li>\n<li>函数通过收到的事件数据获得了 Bucket 名称和文件名称，从该源 Bucket中获取该文件，根据代码中实现的 wordcount 进行字数统计，然后将其保存到目标 Bucket 上。</li>\n</ul>\n<p>部署成功后，本模版将会为您创建以下资源：</p>\n<ul>\n<li>两个 SCF 函数：Mapper 和 Reducer。</li>\n<li>三个 COS Bucket：srcmr、middlestagebucket 和 destmr。</li>\n<li>Mapper 函数将会绑定 srcmr 触发，Reducer 函数将会绑定 middlestagebucket 触发，destmr 将会用来接收最终的统计结果。</li>\n</ul>\n<h2 id=\"开发步骤\"><a href=\"#%E5%BC%80%E5%8F%91%E6%AD%A5%E9%AA%A4\" 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<ol>\n<li>通过 COS 组件完成创建上传文件的 COS 存储桶的配置文件编写，yml 文件配置如下</li>\n</ol>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"87128096281935990000\"\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(`# serverless.yml\norg: serverless\napp: MapReduce_Demo\nstage: dev\ncomponent: cos\nname: destmr\n\ninputs:\n  bucket: destmr\n  region: ap-guangzhou`, `87128096281935990000`)\"\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=\"text\"><pre class=\"language-text\"><code class=\"language-text\"># serverless.yml\norg: serverless\napp: MapReduce_Demo\nstage: dev\ncomponent: cos\nname: destmr\n\ninputs:\n  bucket: destmr\n  region: ap-guangzhou</code></pre></div>\n<p>同理，完成其它两个存储桶配置。</p>\n<ol start=\"2\">\n<li>完成函数代码编写，本模版中需要创建两个函数：Map 函数与 Reduce 函数，并为其分别配置 yml 文件</li>\n</ol>\n<p>Map 函数 yml 文件示例如下：</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"46795568036779470000\"\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(`component: scf # (必选) 组件名称，在该实例中为scf\nname: map_function # 必选) 组件实例名称.\norg: serverless # (可选) 用于记录组织信息，\napp: MapReduce_Demo # (可选) 用于您的 AP名称\nstage: dev # (可选) 用于区分环境信息，默认值是 dev\n\ninputs:\n  name: map_function\n  src: ./\n  handler: map_function.main_handler \n  runtime: Python2.7 \n  region: ap-guangzhou \n  description: This is one of the MapReduce function which is map_function\n  memorySize: 128 \n  timeout: 10\n  environment:\n    variables:\n        Bucket: \\${output:\\${stage}:\\${app}:middlestagebucket.bucket}\n        TENCENT_SECRET_ID: \\${env:TENCENT_SECRET_ID}\n        TENCENT_SECRET_KEY: \\${env:TENCENT_SECRET_KEY}\n  \n  events: # 触发器\n    - cos: # cos触发器\n        name: \\${output:\\${stage}:\\${app}:srcmr.cosOrigin}\n        parameters:\n          bucket: \\${output:\\${stage}:\\${app}:srcmr.cosOrigin}\n          events: 'cos:ObjectCreated:*'\n          enable: true`, `46795568036779470000`)\"\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=\"text\"><pre class=\"language-text\"><code class=\"language-text\">component: scf # (必选) 组件名称，在该实例中为scf\nname: map_function # 必选) 组件实例名称.\norg: serverless # (可选) 用于记录组织信息，\napp: MapReduce_Demo # (可选) 用于您的 AP名称\nstage: dev # (可选) 用于区分环境信息，默认值是 dev\n\ninputs:\n  name: map_function\n  src: ./\n  handler: map_function.main_handler \n  runtime: Python2.7 \n  region: ap-guangzhou \n  description: This is one of the MapReduce function which is map_function\n  memorySize: 128 \n  timeout: 10\n  environment:\n    variables:\n        Bucket: ${output:${stage}:${app}:middlestagebucket.bucket}\n        TENCENT_SECRET_ID: ${env:TENCENT_SECRET_ID}\n        TENCENT_SECRET_KEY: ${env:TENCENT_SECRET_KEY}\n  \n  events: # 触发器\n    - cos: # cos触发器\n        name: ${output:${stage}:${app}:srcmr.cosOrigin}\n        parameters:\n          bucket: ${output:${stage}:${app}:srcmr.cosOrigin}\n          events: &#39;cos:ObjectCreated:*&#39;\n          enable: true</code></pre></div>\n<ol start=\"3\">\n<li>完成配置后，整个应用模版结构如下：</li>\n</ol>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"28035511963833270000\"\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(`Map_Reduce_Demo\n|--bucket_destmr\n  |--serverless.yml\n|--bucket_middlestage\n  |--serverless.yml\n|--bucket_srcmr\n  |--serverless.yml\n|--fun_map\n  |--serverless.yml\n  |--map_function.py\n|--fun_reduce\n  |--serverless.yml\n  |--reduce_function.py`, `28035511963833270000`)\"\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=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Map_Reduce_Demo\n|--bucket_destmr\n  |--serverless.yml\n|--bucket_middlestage\n  |--serverless.yml\n|--bucket_srcmr\n  |--serverless.yml\n|--fun_map\n  |--serverless.yml\n  |--map_function.py\n|--fun_reduce\n  |--serverless.yml\n  |--reduce_function.py</code></pre></div>\n<p>您也可根据您的实际业务逻辑进行更改。</p>\n<h2 id=\"模版上传\"><a href=\"#%E6%A8%A1%E7%89%88%E4%B8%8A%E4%BC%A0\" 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>完成模版开发后，您可以将您的模版上传至 Registry，供大家公开复用。</p>\n<ol>\n<li>在项目根目录下配置上传至 Registry 的项目模版信息：</li>\n</ol>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"17136171144094691000\"\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(`# serverless.yml\nname: mapreduce-demo # 项目模板的名字\ndisplayName: 基于 MapReduce 统计字数  #项目模板展示在控制台的名称（中文）\nauthor: Tencent Cloud, Inc. # 作者的名字\norg: Tencent Cloud, Inc. # 组织名称，可选\ntype: template #项目类型，可填 template 或 component，此处为模版\ndescription: Deploy a MapReduce wordcount application. # 描述您的项目模板\ndescription-i18n:\n  zh-cn: 本示例Demo演示怎么利用COS来做MapReduce，一共需要2个函数：map_function和reduce_function，3个COS Bucket：srcmr、middlestagebucket 和 destmr # 中文描述\nkeywords: tencent, serverless, cos, scf, mapreduce # 关键字\nrepo: # 源代码 Repo\nreadme: # 详细的说明文件\nlicense: MIT # 版权声明\nsrc: # 描述项目中的哪些文件需要作为模板发布\n  src: ./ # 指定具体的相对目录，此目录下的文件将作为模板发布\n  exclude: #描述在指定的目录内哪些文件应该被排除\n    - .env\n    - serverless.yml`, `17136171144094691000`)\"\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=\"text\"><pre class=\"language-text\"><code class=\"language-text\"># serverless.yml\nname: mapreduce-demo # 项目模板的名字\ndisplayName: 基于 MapReduce 统计字数  #项目模板展示在控制台的名称（中文）\nauthor: Tencent Cloud, Inc. # 作者的名字\norg: Tencent Cloud, Inc. # 组织名称，可选\ntype: template #项目类型，可填 template 或 component，此处为模版\ndescription: Deploy a MapReduce wordcount application. # 描述您的项目模板\ndescription-i18n:\n  zh-cn: 本示例Demo演示怎么利用COS来做MapReduce，一共需要2个函数：map_function和reduce_function，3个COS Bucket：srcmr、middlestagebucket 和 destmr # 中文描述\nkeywords: tencent, serverless, cos, scf, mapreduce # 关键字\nrepo: # 源代码 Repo\nreadme: # 详细的说明文件\nlicense: MIT # 版权声明\nsrc: # 描述项目中的哪些文件需要作为模板发布\n  src: ./ # 指定具体的相对目录，此目录下的文件将作为模板发布\n  exclude: #描述在指定的目录内哪些文件应该被排除\n    - .env\n    - serverless.yml</code></pre></div>\n<ol start=\"2\">\n<li>上传模版</li>\n</ol>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"85127363836823490000\"\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(`\\$ sls registry publish\nserverless ⚡ registry\nPublishing &quot;mapreduce-demo@0.0.0&quot;...\n\nServerless › Successfully published mapreduce-demo`, `85127363836823490000`)\"\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=\"console\"><pre class=\"language-console\"><code class=\"language-console\">$ sls registry publish\nserverless ⚡ registry\nPublishing &quot;mapreduce-demo@0.0.0&quot;...\n\nServerless › Successfully published mapreduce-demo</code></pre></div>\n<h2 id=\"模版复用\"><a href=\"#%E6%A8%A1%E7%89%88%E5%A4%8D%E7%94%A8\" 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>所有上传到 Registry的模版都支持公开下载与复用的，操作如下：</p>\n<ol>\n<li>下载模版</li>\n</ol>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"70553589431986490000\"\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(`\\$ sls init -t mapreduce-demo\nserverless ⚡ framework\n\n- Successfully created &quot;mapreduce-demo&quot; instance in the currennt working directory.\n- Don't forget to update serverless.yml and install dependencies if needed.\n- Whenever you're ready, run &quot;serverless deploy&quot; to deploy your new instance.\n\nmapreduce-demo › Created`, `70553589431986490000`)\"\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=\"console\"><pre class=\"language-console\"><code class=\"language-console\">$ sls init -t mapreduce-demo\nserverless ⚡ framework\n\n- Successfully created &quot;mapreduce-demo&quot; instance in the currennt working directory.\n- Don&#39;t forget to update serverless.yml and install dependencies if needed.\n- Whenever you&#39;re ready, run &quot;serverless deploy&quot; to deploy your new instance.\n\nmapreduce-demo › Created</code></pre></div>\n<ol start=\"2\">\n<li>在环境配置 .env 文件中填入您自己的密钥信息</li>\n</ol>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"46186680962184050000\"\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(`# .env\nTENCENT_SECRET_ID=123\nTENCENT_SECRET_KEY=123`, `46186680962184050000`)\"\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=\"text\"><pre class=\"language-text\"><code class=\"language-text\"># .env\nTENCENT_SECRET_ID=123\nTENCENT_SECRET_KEY=123</code></pre></div>\n<ol start=\"3\">\n<li>部署项目</li>\n</ol>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"1150700711704777300\"\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(`\\$ cd mapreduce-demo\n\\$ sls deploy --all\nserverless ⚡ framework\n\nsrcmr: \n  region:        ap-guangzhou\n  bucket:        srcmr-0000000000\n  cosOrigin:     srcmr-0000000000.cos.ap-guangzhou.myqcloud.com\n  url:           http://srcmr-0000000000.cos.ap-guangzhou.myqcloud.com\n  vendorMessage: null\n\ndestmr: \n  region:        ap-guangzhou\n  bucket:        destmr-0000000000\n  cosOrigin:     destmr-0000000000.cos.ap-guangzhou.myqcloud.com\n  url:           http://destmr-0000000000.cos.ap-guangzhou.myqcloud.com\n  vendorMessage: null\n\nmiddlestagebucket: \n  region:        ap-guangzhou\n  bucket:        middlestagebucket-0000000000\n  cosOrigin:     middlestagebucket-0000000000.cos.ap-guangzhou.myqcloud.com\n  url:           http://middlestagebucket-0000000000.cos.ap-guangzhou.myqcloud.com\n  vendorMessage: null\n\nmap_function: \n  functionName:  map_function\n  description:   This is one of the MapReduce function which is map_function\n  namespace:     default\n  runtime:       Python2.7\n  handler:       map_function.main_handler\n  memorySize:    128\n  lastVersion:   \\$LATEST\n  traffic:       1\n  triggers: \n    cos: \n      - srcmr-0000000000.cos.ap-guangzhou.myqcloud.com\n  vendorMessage: null\n\nreduce-function: \n  functionName:  reduce_function\n  description:   This is one of the MapReduce function which is reduce_function\n  namespace:     default\n  runtime:       Python2.7\n  handler:       reduce_function.main_handler\n  memorySize:    128\n  lastVersion:   \\$LATEST\n  traffic:       1\n  triggers: \n    cos: \n      - middlestagebucket-0000000000.cos.ap-guangzhou.myqcloud.com\n  vendorMessage: null\n\n8s › mapreduce-demo › Success`, `1150700711704777300`)\"\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=\"console\"><pre class=\"language-console\"><code class=\"language-console\">$ cd mapreduce-demo\n$ sls deploy --all\nserverless ⚡ framework\n\nsrcmr: \n  region:        ap-guangzhou\n  bucket:        srcmr-0000000000\n  cosOrigin:     srcmr-0000000000.cos.ap-guangzhou.myqcloud.com\n  url:           http://srcmr-0000000000.cos.ap-guangzhou.myqcloud.com\n  vendorMessage: null\n\ndestmr: \n  region:        ap-guangzhou\n  bucket:        destmr-0000000000\n  cosOrigin:     destmr-0000000000.cos.ap-guangzhou.myqcloud.com\n  url:           http://destmr-0000000000.cos.ap-guangzhou.myqcloud.com\n  vendorMessage: null\n\nmiddlestagebucket: \n  region:        ap-guangzhou\n  bucket:        middlestagebucket-0000000000\n  cosOrigin:     middlestagebucket-0000000000.cos.ap-guangzhou.myqcloud.com\n  url:           http://middlestagebucket-0000000000.cos.ap-guangzhou.myqcloud.com\n  vendorMessage: null\n\nmap_function: \n  functionName:  map_function\n  description:   This is one of the MapReduce function which is map_function\n  namespace:     default\n  runtime:       Python2.7\n  handler:       map_function.main_handler\n  memorySize:    128\n  lastVersion:   $LATEST\n  traffic:       1\n  triggers: \n    cos: \n      - srcmr-0000000000.cos.ap-guangzhou.myqcloud.com\n  vendorMessage: null\n\nreduce-function: \n  functionName:  reduce_function\n  description:   This is one of the MapReduce function which is reduce_function\n  namespace:     default\n  runtime:       Python2.7\n  handler:       reduce_function.main_handler\n  memorySize:    128\n  lastVersion:   $LATEST\n  traffic:       1\n  triggers: \n    cos: \n      - middlestagebucket-0000000000.cos.ap-guangzhou.myqcloud.com\n  vendorMessage: null\n\n8s › mapreduce-demo › Success</code></pre></div>\n<h2 id=\"项目测试\"><a href=\"#%E9%A1%B9%E7%9B%AE%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<ol>\n<li>找到模版文档中的 test.txt 文件。</li>\n<li>切换至<a href=\"https://console.cloud.tencent.com/cos/bucket\">对象存储控制台</a>，选择创建好的 Bucket：srcmr，单击「上传文件」。</li>\n<li>在弹出的「上传文件」窗口中，选择 test.txt，单击「确定上传」。</li>\n<li>切换至<a href=\"https://console.cloud.tencent.com/scf/list?rid=8&#x26;ns=default\">云函数控制台</a>，查看执行结果。在运行日志中可以看到打印出来的日志信息。</li>\n<li>切换至 <a href=\"https://console.cloud.tencent.com/cos/bucket\">对象存储控制台</a>，选择创建好的 Bucket：destmr，查看生成的文件。</li>\n</ol>\n<h2 id=\"项目移除\"><a href=\"#%E9%A1%B9%E7%9B%AE%E7%A7%BB%E9%99%A4\" 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>可以通过以下命令移除应用</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"71801028509297705000\"\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(`\\$ sls remove --all\n\nserverless ⚡ framework\n\n8s › maprecude › Success\n  `, `71801028509297705000`)\"\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=\"console\"><pre class=\"language-console\"><code class=\"language-console\">$ sls remove --all\n\nserverless ⚡ framework\n\n8s › maprecude › Success\n  </code></pre></div>\n<hr>\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=\"/best-practice/2020-07-16-registry-mapreduce/#%E5%89%8D%E6%8F%90%E6%9D%A1%E4%BB%B6\">前提条件</a></li>\n<li><a href=\"/best-practice/2020-07-16-registry-mapreduce/#%E5%AE%9E%E7%8E%B0%E6%A6%82%E8%A6%81\">实现概要</a></li>\n<li><a href=\"/best-practice/2020-07-16-registry-mapreduce/#%E5%BC%80%E5%8F%91%E6%AD%A5%E9%AA%A4\">开发步骤</a></li>\n<li><a href=\"/best-practice/2020-07-16-registry-mapreduce/#%E6%A8%A1%E7%89%88%E4%B8%8A%E4%BC%A0\">模版上传</a></li>\n<li><a href=\"/best-practice/2020-07-16-registry-mapreduce/#%E6%A8%A1%E7%89%88%E5%A4%8D%E7%94%A8\">模版复用</a></li>\n<li><a href=\"/best-practice/2020-07-16-registry-mapreduce/#%E9%A1%B9%E7%9B%AE%E6%B5%8B%E8%AF%95\">项目测试</a></li>\n<li><a href=\"/best-practice/2020-07-16-registry-mapreduce/#%E9%A1%B9%E7%9B%AE%E7%A7%BB%E9%99%A4\">项目移除</a></li>\n</ul>"},"previousBlog":{"id":"40b4ebd6-7c3e-5418-9203-3222d32b7b90","frontmatter":{"thumbnail":"https://img.serverlesscloud.cn/2020731/1596192531300-1596186208253-%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_15961861933543.jpg","authors":["粟俊娥"],"categories":["best-practice"],"date":"2020-07-31T00:00:00.000Z","title":"腾讯云 Serverless CI/CD 自动化部署实战","description":"本文将为大家讲解 Serverless 工作原理、架构优势和 Serverless 应用的开发流程，以及如何使用 Serverless CI/CD 能力进行自动化部署。","authorslink":["https://github.com/June1991"],"translators":null,"translatorslink":null,"tags":["CI/CD","Meetup"],"keywords":"Serverless, ServerlessDays, Serverless DevOps","outdated":null},"wordCount":{"words":246,"sentences":47,"paragraphs":47},"fileAbsolutePath":"/opt/build/repo/content/best-practice/2020-07-31-serverless-cicd.md","fields":{"slug":"/best-practice/2020-07-31-serverless-cicd/","keywords":["serverless","无服务器","云函数","Serverless","开发","serverless","部署","video"]}},"nextBlog":{"id":"a95f844d-eae9-5465-b1e8-d5dcd4464453","frontmatter":{"thumbnail":"https://img.serverlesscloud.cn/2020713/1594610687799-Nextjs-93.jpg","authors":["Yugasun"],"categories":["best-practice"],"date":"2020-07-12T00:00:00.000Z","title":"如何优雅地部署一个 Serverless Next.js 应用","description":"本篇专门针对 Next.js 的 SSR 方案进行了探索和优化，一步一步带大家了解，如何基于 Serverless 架构部署一个实际的线上业务","authorslink":["https://github.com/yugasun"],"translators":null,"translatorslink":null,"tags":["Serverless SSR","Next.js"],"keywords":"Serverless SSR,Serverless Egg.js","outdated":null},"wordCount":{"words":478,"sentences":81,"paragraphs":81},"fileAbsolutePath":"/opt/build/repo/content/best-practice/2020-07-12-serverless-nextjs.md","fields":{"slug":"/best-practice/2020-07-12-serverless-nextjs/","keywords":["nextjs","serverless","ssr","云函数","serverless","Next","部署","nextjs","静态","Serverless","Layer"]}}},"pageContext":{"isCreatedByStatefulCreatePages":false,"blogId":"ca884fd4-891f-599b-ac9f-b6f1169df802","previousBlogId":"40b4ebd6-7c3e-5418-9203-3222d32b7b90","nextBlogId":"a95f844d-eae9-5465-b1e8-d5dcd4464453"}}}