{"id":88229,"date":"2020-02-09T19:27:43","date_gmt":"2020-02-09T11:27:43","guid":{"rendered":"http:\/\/4563.org\/?p=88229"},"modified":"2020-02-09T19:27:43","modified_gmt":"2020-02-09T11:27:43","slug":"%e5%ae%9e%e9%aa%8c%e5%ae%a4%e7%ab%99%e8%bf%81%e7%a7%bb-serverless-%e4%b9%8b%e8%b7%af%ef%bc%88%e4%b8%8a%ef%bc%89","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=88229","title":{"rendered":"\u5b9e\u9a8c\u5ba4\u7ad9\u8fc1\u79fb Serverless \u4e4b\u8def\uff08\u4e0a\uff09"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u5b9e\u9a8c\u5ba4\u7ad9\u8fc1\u79fb Serverless \u4e4b\u8def\uff08\u4e0a\uff09               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : scf10cent <\/span>  <span><i><\/i> 22<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<pre><code>\u672c\u6587\u4e3a Serverless \u793e\u533a\u6210\u5458\u64b0\u7a3f\u3002\u4f5c\u8005\u9ad8\u6668\u8fdc\uff0c\u7814\u53d1\u5de5\u7a0b\u5e08\uff0c\u719f\u6089 Python \u5f00\u53d1\uff0c\u5e38\u5199 Web \u548c\u722c\u866b <\/code><\/pre>\n<h2>\u524d\u8a00<\/h2>\n<p>2 \u6708\u4efd\uff0cTencentServerless \u4e3e\u529e\u4e86\u7cfb\u5217\u5728\u7ebf\u8bfe\u5802\u5206\u4eab\uff0c\u8bb2\u89e3\u4e86 Serverless \u6982\u5ff5\u3001\u67b6\u6784\u3001\u6700\u4f73\u5b9e\u8df5\u4ee5\u53ca\u5982\u4f55\u5f00\u53d1\u4e00\u4e2a component \u7b49\u6280\u672f\u77e5\u8bc6\u3002<\/p>\n<p>\u56e0\u4e3a\u5bf9 Serverless \u975e\u5e38\u611f\u5174\u8da3\uff0c\u6bcf\u6b21\u90fd\u53c2\u52a0\u4e86\u76f4\u64ad\u5b66\u4e60\u5e76\u63d0\u4ea4\u4e86\u8bfe\u5802\u4f5c\u4e1a\uff0c\u4e00\u8def\u4e0b\u6765\u611f\u89c9\u8fd8\u4e0d\u9519\uff0c\u56e0\u6b64\u51b3\u5b9a\u628a\u81ea\u5df1\u7684\u5b9e\u9a8c\u5ba4\u7ad9\u8fc1\u79fb\u5230 Serverless \u8bd5\u8bd5\u770b\u3002<\/p>\n<h2>1. TencentServerless \u4ecb\u7ecd<\/h2>\n<p>\u4e0d\u5f97\u4e0d\u611f\u53f9\u4e92\u8054\u7f51\u65f6\u4ee3\u79d1\u6280\u7684\u8fdb\u6b65\uff0c\u4e4b\u524d\u6211\u7684\u5b9e\u9a8c\u5ba4\u7ad9\u91c7\u7528\u7684\u662f\u4f20\u7edf\u65b9\u6cd5\u53d1\u5e03\u7f51\u7ad9\u7684\u73af\u5883\u90e8\u7f72\uff0c\u867d\u7136\u73b0\u5728\u719f\u6089\u4e86\u64cd\u4f5c\u5e76\u4e0d\u89c9\u5f97\u5f88\u9ebb\u70e6\uff0c\u4f46\u662f\u5bf9\u4e8e\u4ece\u6765\u6ca1\u63a5\u89e6\u8fc7\u8fd9\u5757\u7684\u4eba\u6765\u8bf4\u5c31\u6bd4\u8f83\u96be\u61c2\u4e86\u3002<\/p>\n<p>\u800c\u73b0\u5728\u6709\u4e86 Serverless\uff0c\u5c31\u53ef\u4ee5\u5b8c\u5168\u65e0\u89c6\u4e0a\u9762\u7684\u64cd\u4f5c\u6b65\u9aa4\u4e86\uff0c\u8fd9\u91cc\u5f15\u7528\u5b98\u7f51\u7684\u4e24\u6bb5\u8bdd\uff1a<\/p>\n<blockquote>\n<p>Serverless Framework \u53ef\u4ee5\u5e2e\u60a8\u4ee5\u66f4\u5c11\u7684\u6210\u672c\u548c\u5f00\u9500, \u5feb\u901f\u6784\u5efa Serverless \u5e94\u7528\u3002\u5b83\u80fd\u591f\u5b8c\u7f8e\u652f\u6301\u65e0\u670d\u52a1\u5668\u5e94\u7528\u7684\u5f00\u53d1\uff0c\u90e8\u7f72\uff0c\u6d4b\u8bd5\uff0c\u76d1\u63a7\u7b49\u73af\u8282\u3002Serverless \u662f\u9762\u5411\u672a\u6765\u7684\u8fd0\u7ef4\u65b9\u5f0f\u3002<\/p>\n<p>Serverless \u5efa\u7acb\u5728\u4e0b\u4e00\u4ee3\u516c\u5171\u4e91\u670d\u52a1\u4e4b\u4e0a\uff0c\u8be5\u670d\u52a1\u4ec5\u5728\u4f7f\u7528\u65f6\u81ea\u52a8\u6269\u5bb9\u548c\u6536\u8d39\u3002\u5f53\u89c4\u6a21\uff0c\u6240\u7528\u5bb9\u91cf\u548c\u6210\u672c\u7ba1\u7406\u5b9e\u73b0\u81ea\u52a8\u5316\u65f6\uff0c\u53ef\u8282\u7701 99% \u7684\u6210\u672c\u7ba1\u7406\u3002<\/p>\n<p>\u65e0\u670d\u52a1\u5668\u67b6\u6784\u662f\u5168\u65b0\u7684\uff0c\u56e0\u6b64\u6211\u4eec\u9700\u8981\u6539\u53d8\u5148\u524d\u5bf9\u8001\u67b6\u6784\u548c\u5de5\u4f5c\u6d41\u7684\u770b\u6cd5\u3002Serverless Framework \u7684\u76ee\u6807\u662f\u4ee5\u4e00\u79cd\u7b80\u5355\uff0c\u5f3a\u5927\u800c\u4f18\u96c5\u7684\u4f7f\u7528\u4f53\u9a8c\u4e3a\u5f00\u53d1\u8005\u3001\u56e2\u961f\u63d0\u4f9b\u5f00\u53d1\u548c\u8fd0\u884c serverless \u5e94\u7528\u7a0b\u5e8f\u6240\u9700\u7684\u6240\u6709\u5de5\u5177\u3002<\/p>\n<\/blockquote>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u975e\u5e38\u65b9\u4fbf\uff0c\u672c\u4eba\u73b0\u5728\u5012\u662f\u89c9\u5f97\u5bf9\u4e8e\u4e2a\u4eba\u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u5982\u679c\u60f3\u6784\u5efa\u8f7b\u91cf\u5e94\u7528\u7684\u8bdd\uff0c\u7528 Serverless \u5e94\u8be5\u4f1a\u8282\u7701\u975e\u5e38\u591a\u7684\u65f6\u95f4\u3002\u5f53\u7136 Serverless \u5bf9\u6bd4\u4f20\u7edf\u578b\u5e94\u7528\u8fd8\u662f\u6709\u533a\u522b\u7684\uff0c\u76ee\u524d\u5b83\u5e76\u4e0d\u80fd\u5b8c\u7f8e\u652f\u6301\uff0c\u4e3e\u4e00\u4e2a\u4f8b\u5b50\uff1aFlask CLI \u5c31\u4e0d\u652f\u6301\uff0c\u4e0d\u8fc7\u76f8\u4fe1\u968f\u7740 Serverless \u6280\u672f\u7684\u53d1\u5c55\uff0cServerless \u7684\u652f\u6301\u5c06\u66f4\u52a0\u5168\u9762\u3002<\/p>\n<p>\u5bf9\u4e8e\u4f01\u4e1a\u5f00\u53d1\u8005\u6765\u8bf4\u4e5f\u662f\u540c\u7406\u7684\uff0c\u60f3\u5feb\u901f\u4e0a\u7ebf\u4e00\u5957\u7f51\u7ad9\u7684\u8bdd\uff0c\u90e8\u7f72\u5728\u4e00\u4e2a\u670d\u52a1\u5668\u4e0a\u5012\u662f\u597d\u8bf4\uff0c\u53ef\u662f\u5f53\u8bbf\u95ee\u91cf\u4e0a\u5347\u4e4b\u540e\uff0c\u9700\u8981\u6269\u5bb9\u7684\u65f6\u5019\u5c31\u6bd4\u8f83\u9ebb\u70e6\u4e86\uff0c\u8fd9\u65f6\u5019\u4f60\u5f97\u5728\u591a\u4e2a\u670d\u52a1\u5668\u4e0a\u90e8\u7f72\u5e76\u4e14\u914d\u7f6e\u8d1f\u8f7d\u5747\u8861\u7b49\u7b49\u3002<\/p>\n<p>\u5bf9\u6211\u4e2a\u4eba\u6765\u8bf4\uff0c\u6211\u89c9\u5f97 Serverless \u6700\u5927\u7684\u4f18\u70b9\u5728\u4e8e\u8fd0\u7ef4\u90e8\u7f72\u65b9\u9762\uff0c\u901a\u8fc7 Serverless \u90e8\u7f72\uff0c\u8fd8\u662f\u975e\u5e38\u65b9\u4fbf\u7684\u3002<\/p>\n<h2>2. \u5b89\u88c5 Serverless Framework<\/h2>\n<p>Serverless Framework \u662f\u57fa\u4e8e Node.js \u7684\u5f00\u6e90 CLI\uff0c\u6ce8\uff1a\u9700 Node 8+ \u5168\u5c40\u5b89\u88c5\uff1a<\/p>\n<pre><code>npm install serverless -g <\/code><\/pre>\n<p>\u8fd9\u91cc\u6ca1\u6709\u4f7f\u7528 cnpm \u7684\u539f\u56e0\u662f\u56e0\u4e3a\u7f51\u7edc\u8fd8\u7b97 ok \u6ca1\u6709\u7279\u522b\u8017\u65f6\uff0c\u53e6\u5916\u5fd8\u8bb0\u4e86\u4e4b\u524d\u5728\u54ea\u91cc\u770b\u5230\u8fc7 cnpm \u4e0d\u4f1a\u66f4\u65b0 package-lock.json\uff0c\u56e0\u6b64\u4e5f\u5c31\u6ca1\u6709\u518d\u53bb\u7528\u7b2c\u4e09\u65b9\u6e90\u3002\u4e4b\u540e\u66f4\u65b0\u7684\u8bdd\u5c31<\/p>\n<pre><code>npm install serverless -g <\/code><\/pre>\n<p>\u5b98\u7f51\u7684\u5feb\u901f\u5f00\u59cb\u6559\u7a0b\u4e4b\u540e\u5feb\u901f\u90e8\u7f72\u4e86\u4e2a demo\uff0c\u5373\uff1a<\/p>\n<pre><code>serverless create -t tencent-nodejs <\/code><\/pre>\n<p>\u547d\u4ee4\u91cc\u7684 tencent-nodejs \u662f\u4f17\u591a\u7ec4\u4ef6\u4e2d\u7684\u4e00\u4e2a\uff0c\u7ec4\u4ef6\u5217\u8868\uff1a https:\/\/github.com\/serverless\/components<\/p>\n<h2>3. \u90e8\u7f72 Python Flask \u6846\u67b6<\/h2>\n<p>\u56e0\u4e3a\u672c\u4eba\u5bf9 Flask \u8fd8\u7b97\u719f\u6089\uff0c\u6240\u4ee5\u5e72\u8106\u628a\u90e8\u7f72\u8fd9\u4e2a Component \u5f53\u6210 Hello World \u597d\u4e86\u3002\u5176\u4e2d\u5b98\u7f51\u7b80\u4ecb\u91cc\u5199\u9053\uff1a\u4efb\u4f55\u652f\u6301 WSGI \uff08 Web Server Gateway Interface \uff09\u7684 Python \u670d\u52a1\u7aef\u6846\u67b6\u90fd\u53ef\u4ee5\u901a\u8fc7\u8be5\u7ec4\u4ef6\u8fdb\u884c\u90e8\u7f72\uff0c\u4f8b\u5982 Falcon \u6846\u67b6\u7b49\u3002<\/p>\n<p><strong>1) \u521b\u5efa\u65b0\u9879\u76ee<\/strong><\/p>\n<ul>\n<li>\n<h4>\u57fa\u4e8e\u6a21\u677f<\/h4>\n<\/li>\n<\/ul>\n<p>\u901a\u8fc7 sls \u76f4\u63a5\u6839\u636e\u6a21\u677f\u521b\u5efa\u670d\u52a1\uff0cServerless github \u4e0a\u6709\u5f88\u591a\u6a21\u677f \u6bd4\u5982\uff1a https:\/\/github.com\/serverless\/components\/tree\/master\/templates\/tencent-flask<\/p>\n<pre><code>serverless create --template-url https:\/\/github.com\/serverless\/components\/tree\/master\/templates\/tencent-flask <\/code><\/pre>\n<p>\u6e90\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code># -*- coding: utf8 -*-   import json from flask import Flask, jsonify, request app = Flask(__name__)     @app.route(\"\/\") def index():     return \"Hello Flash\"   @app.route('\/user', methods = ['POST']) def addUser():     # we must get request body from clound function event;     event = request.environ['event']     user = json.loads(event['body'])     return jsonify(data=user)     @app.route(\"\/user\", methods = ['GET']) def listUser():     users = [{'name': 'test1'}, {'name': 'test2'}]     return jsonify(data=users)     @app.route(\"\/user\/&lt;id&gt;\", methods = ['GET']) def getUser(id):     return jsonify(data={'name': 'test1'}) <\/code><\/pre>\n<ul>\n<li>\u4e0d\u57fa\u4e8e\u6a21\u677f<\/li>\n<\/ul>\n<p>\u5728 Pycharm \u521b\u5efa\u4e00\u4e2a\u65b0\u7684 Flask \u9879\u76ee\uff1aLAB_Serverless \u4ee5\u533a\u522b\u4e4b\u524d\u7684 LAB<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/05\/20200517_5ec11429adf36.jpg\" alt=\"\u5b9e\u9a8c\u5ba4\u7ad9\u8fc1\u79fb Serverless \u4e4b\u8def\uff08\u4e0a\uff09\" \/><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/05\/20200517_5ec11430c8e5a.jpg\" alt=\"\u5b9e\u9a8c\u5ba4\u7ad9\u8fc1\u79fb Serverless \u4e4b\u8def\uff08\u4e0a\uff09\" \/><\/p>\n<p>\u6e90\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code>from flask import Flask   app = Flask(__name__)   @app.route('\/') def hello_world():     return 'Hello World!'   if __name__ == '__main__':     app.run() <\/code><\/pre>\n<p><strong>2) \u914d\u7f6e Serverless<\/strong><\/p>\n<ul>\n<li>\u521b\u5efa serverless.yml \uff0c\u8fd9\u91cc\u66f4\u6539\u4e86\u51e0\u5904\u914d\u7f6e<\/li>\n<\/ul>\n<pre><code> MyComponent:   component: '@serverless\/tencent-flask'   inputs:     region: ap-beijing     functionName: LAB_Serverless     code: .\/     functionConf:       timeout: 10       memorySize: 128       environment:         variables:           TEST: value           Version: 2020-2-23_21:01:44       vpcConfig:         subnetId: ''         vpcId: ''     apigatewayConf:       protocol: https       environment: test  <\/code><\/pre>\n<ul>\n<li>\u521b\u5efa.env \uff0c\u5199\u5165\u5bc6\u5319\uff08\u56e0\u4e3a\u61d2\u5f97\u6bcf\u6b21\u90e8\u7f72\u90fd\u5f97\u62ff\u8d77\u624b\u673a\u626b\u4e00\u626b\u6388\u6743(^_\u2212)\u2606<\/li>\n<\/ul>\n<pre><code>TENCENT_SECRET_ID=&lt;rm&gt; TENCENT_SECRET_KEY=&lt;rm&gt; <\/code><\/pre>\n<p><strong>3) \u90e8\u7f72<\/strong><\/p>\n<p>serverless \u7684\u7f29\u5199\u662f sls\uff0c\u56e0\u6b64\u4e5f\u53ef\u4ee5\u7528 sls \u7b80\u5316\u547d\u4ee4\u3002\u4f46\u662f\u8fd9\u91cc\u62a5\u9519\u4e86\u2026\u2026\u62a5\u9519\u7684\u539f\u56e0\u662f requirements \u6587\u4ef6\u5939\u4e0d\u5b58\u5728\u3002<\/p>\n<p>\u67e5\u770b\u7ec8\u7aef<\/p>\n<pre><code>Microsoft Windows [\u7248\u672c 10.0.17763.1039] (c) 2018 Microsoft Corporation \u3002\u4fdd\u7559\u6240\u6709\u6743\u5229\u3002   D:yuangezhizaoDocumentsPycharmProjectsLAB_Serverless&gt;sls --debug     DEBUG\u2500Resolving the template's static variables.   DEBUG\u2500Collecting components from the template.   DEBUG\u2500Downloading any NPM components found in the template.   DEBUG\u2500Analyzing the template's components dependencies.   DEBUG\u2500Creating the template's components graph.   DEBUG\u2500Syncing template state.   DEBUG\u2500Executing the template's components graph.   DEBUG\u2500Compressing function LAB_Serverless file to D:yuangezhizaoDocumentsPycharmProjectsLAB_Serverless.serverless\/LAB_Serverless.zip. (node:22500) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, stat 'D:yuangezhizaoDocumentsPycharmProjectsLAB_Serverless. serverlessrequirements'eploying     at Object.statSync (fs.js:946:3)     at Object.statSync (C:UsersyuangezhizaoAppDataRoamingnpmnode_modulesserverlessnode_modules[email&#160;protected]@graceful-fspolyfills.js:308:16 )     at WriteStream.&lt;anonymous&gt; (C:Usersyuangezhizao.serverlesscomponentsregistrynpm@serverless[email&#160;protected]node_modules@serverlesstencen t-flasknode_modules@serverlesstencent-scflibraryutils.js:124:20)     at WriteStream.emit (events.js:304:20)     at C:Usersyuangezhizao.serverlesscomponentsregistrynpm@serverless[email&#160;protected]node_modules@serverlesstencent-flasknode_modulesgrac eful-fsgraceful-fs.js:298:14     at C:Usersyuangezhizao.serverlesscomponentsregistrynpm@serverless[email&#160;protected]node_modules@serverlesstencent-flasknode_modulesgrac eful-fsgraceful-fs.js:325:16     at C:UsersyuangezhizaoAppDataRoamingnpmnode_modulesserverlessnode_modules[email&#160;protected]@graceful-fsgraceful-fs.js:325:16     at FSReqCallback.oncomplete (fs.js:152:23) (node:22500) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:22500) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will termi nate the Node.js process with a non-zero exit code.     194s\u00bbMyComponent\u00bbcanceled   \u7ec8\u6b62\u6279\u5904\u7406\u64cd\u4f5c\u5417(Y\/N)? Y   D:yuangezhizaoDocumentsPycharmProjectsLAB_Serverless&gt; <\/code><\/pre>\n<p>\u7136\u540e\u53bb .serverless \u6587\u4ef6\u4e0b\u7684 Template.MyComponent.pyRequirements.json \u6587\u4ef6\u4e2d\u770b\u5230\u4e86 requirements.txt \u3002\u8fd9\u91cc\u5176\u5b9e\u662f\u6545\u610f\u64cd\u4f5c\u7684\uff08\u7279\u610f\u6ca1\u6dfb\u52a0 requirements.txt \uff09\uff0c\u8bf4\u660e requirements.txt \u5fc5\u987b\u5b58\u5728\uff01<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/05\/20200517_5ec114398d4ad.jpg\" alt=\"\u5b9e\u9a8c\u5ba4\u7ad9\u8fc1\u79fb Serverless \u4e4b\u8def\uff08\u4e0a\uff09\" \/><\/p>\n<p>\u56e0\u6b64\uff0c\u53bb\u521b\u5efa\u6587\u4ef6\u5185\u5bb9\u4e3a Flask \u7684 requirements.txt<\/p>\n<pre><code>D:yuangezhizaoDocumentsPycharmProjectsLAB_Serverless&gt;sls --debug     DEBUG\u2500Resolving the template's static variables.   DEBUG\u2500Collecting components from the template.   DEBUG\u2500Downloading any NPM components found in the template.   DEBUG\u2500Analyzing the template's components dependencies.   DEBUG\u2500Creating the template's components graph.   DEBUG\u2500Syncing template state.   DEBUG\u2500Executing the template's components graph.   DEBUG\u2500Generated requirements from D:yuangezhizaoDocumentsPycharmProjectsLAB_Serverlessrequirements.txt in D:yuangezhizaoDocumentsPycharmProje ctsLAB_Serverless.serverlessrequirements.txt...   DEBUG\u2500Installing requirements from C:UsersyuangezhizaoAppDataLocalYugasunserverless-python-requirementsCache2a1a661c4e3e6faadab5d001bc10cc3ac ccf648921aad7c279d94f138eaaf833_slspycrequirements.txt ...   DEBUG\u2500Using download cache directory C:UsersyuangezhizaoAppDataLocalYugasunserverless-python-requirementsCachedownloadCacheslspyc   DEBUG\u2500Running ...   DEBUG\u2500Compressing function LAB_Serverless file to D:yuangezhizaoDocumentsPycharmProjectsLAB_Serverless.serverless\/LAB_Serverless.zip.   DEBUG\u2500Compressed function LAB_Serverless file successful   DEBUG\u2500Uploading service package to cos[sls-cloudfunction-ap-beijing-code]. sls-cloudfunction-default-LAB_Serverless-1582464464.zip   DEBUG\u2500Uploaded package successful D:yuangezhizaoDocumentsPycharmProjectsLAB_Serverless.serverless\/LAB_Serverless.zip   DEBUG\u2500Creating function LAB_Serverless   DEBUG\u2500Created function LAB_Serverless successful   DEBUG\u2500Setting tags for function LAB_Serverless   DEBUG\u2500Creating trigger for function LAB_Serverless   DEBUG\u2500Deployed function LAB_Serverless successful   DEBUG\u2500Starting API-Gateway deployment with name MyComponent.TencentApiGateway in the ap-beijing region   DEBUG\u2500Service with ID service-0ok85tqh created.   DEBUG\u2500API with id api-ivk6tk0y created.   DEBUG\u2500Deploying service with id service-0ok85tqh.   DEBUG\u2500Deployment successful for the api named MyComponent.TencentApiGateway in the ap-beijing region.     MyComponent:     region:              ap-beijing     functionName:        LAB_Serverless     apiGatewayServiceId: service-0ok85tqh     url:                 http:\/\/service-0ok85tqh-1251901037.bj.apigw.tencentcs.com\/test\/     44s\u00bbMyComponent\u00bbdone     D:yuangezhizaoDocumentsPycharmProjectsLAB_Serverless&gt; <\/code><\/pre>\n<p>\u8d81\u673a\u770b\u4e0b\u90e8\u7f72\u6210\u529f\u4e4b\u540e\u7684 .serverless \u6587\u4ef6\u5939\uff1a<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/05\/20200517_5ec11441203da.jpg\" alt=\"\u5b9e\u9a8c\u5ba4\u7ad9\u8fc1\u79fb Serverless \u4e4b\u8def\uff08\u4e0a\uff09\" \/><\/p>\n<p>\u8fd9\u91cc Template.MyComponent.TencentCloudFunction.json \u5373\u4e91\u51fd\u6570<\/p>\n<pre><code>{   \"deployed\": {     \"Name\": \"LAB_Serverless\",     \"Runtime\": \"Python3.6\",     \"Handler\": \"api_service.handler\",     \"MemorySize\": 128,     \"Timeout\": 10,     \"Region\": \"ap-beijing\",     \"Description\": \"This is a template function\"   } } <\/code><\/pre>\n<p>\u7b2c\u4e09\u65b9\u5305\u5168\u5728\u8fd9\u91cc\uff1a<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/05\/20200517_5ec114469ba38.jpg\" alt=\"\u5b9e\u9a8c\u5ba4\u7ad9\u8fc1\u79fb Serverless \u4e4b\u8def\uff08\u4e0a\uff09\" \/><\/p>\n<p>Template.MyComponent.TencentApiGateway.json \u5373 API \u7f51\u5173<\/p>\n<pre><code>{   \"protocols\": [     \"http\"   ],   \"subDomain\": \"service-0ok85tqh-1251901037.bj.apigw.tencentcs.com\",   \"environment\": \"test\",   \"region\": \"ap-beijing\",   \"service\": {     \"value\": \"service-0ok85tqh\",     \"created\": true   },   \"apis\": [     {       \"path\": \"\/\",       \"method\": \"ANY\",       \"apiId\": {         \"value\": \"api-ivk6tk0y\",         \"created\": true       }     }   ] } <\/code><\/pre>\n<p>\u4e5f\u5c31\u662f\u8bf4 CLI \u81ea\u52a8\u5e2e\u6211\u4eec\u521b\u5efa SCF \u5e76\u5c06\u8fd0\u884c\u73af\u5883\u4e00\u5e76\u4e0a\u4f20\uff0c\u518d\u521b\u5efa API \u7f51\u5173\u914d\u7f6e\u5230 SCF \u7684\u89e6\u53d1\u5668\u4e0a\u3002<\/p>\n<pre><code>apigatewayConf:     protocol: https     environment: test <\/code><\/pre>\n<p>\u5230\u8fd9\u91cc demo \u5c31\u641e\u5b9a\u4e86\uff0c\u5df2\u7ecf\u53ef\u4ee5\u6b63\u5e38\u8bbf\u95ee\u4e86 \u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/05\/20200517_5ec1144c13ef5.jpg\" alt=\"\u5b9e\u9a8c\u5ba4\u7ad9\u8fc1\u79fb Serverless \u4e4b\u8def\uff08\u4e0a\uff09\" \/><\/p>\n<h2>4. \u539f\u7406\u6df1\u5165<\/h2>\n<p>\u53bb\u4e91\u51fd\u6570\u770b\u5b9e\u9645\u8fd0\u884c\u73af\u5883\uff0c\u53d1\u73b0\u628a.idea \u6587\u4ef6\u5939\u4e5f\u7ed9\u4e0a\u4f20\u4e86 \u53e6\u5916\uff0c\u591a\u4e86\u5982\u4e0b\u4fe9\u672c\u5730\u6ca1\u6709\u7684\u6587\u4ef6\uff1a<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/05\/20200517_5ec11452ed229.jpg\" alt=\"\u5b9e\u9a8c\u5ba4\u7ad9\u8fc1\u79fb Serverless \u4e4b\u8def\uff08\u4e0a\uff09\" \/><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/05\/20200517_5ec11458edb55.jpg\" alt=\"\u5b9e\u9a8c\u5ba4\u7ad9\u8fc1\u79fb Serverless \u4e4b\u8def\uff08\u4e0a\uff09\" \/><\/p>\n<p>\u5176\u5b9e\u8fd9\u5c31\u662f Serverless \u7684\u6838\u5fc3\u4e86\uff0cServerless \u914d\u7f6e\u9759\u6001\u9875\u9762\u7684\u539f\u7406\u81ea\u5df1\u662f\u6e05\u695a\u7684\u3002\u6bd4\u5982 Hexo \u5c31\u662f\u751f\u6210\u9875\u9762\u4e4b\u540e\u4e0a\u4f20\u5230 COS \u4e0a\u5c31\u80fd\u8bbf\u95ee\u4e86\u3002<\/p>\n<p>\u4f46\u662f\uff0c\u5bf9\u4e8e\u52a8\u6001\u9875\u9762\u5c31\u6bd4\u8f83\u597d\u5947\u4e86\uff0c\u8fd9\u662f\u600e\u4e48\u5b9e\u73b0\u7684\u5462\uff1f\u5176\u5b9e\u5c31\u662f\u9760\u7740 serverless.wsgi \u8fd9\u4e2a\u6587\u4ef6\u7b49\u7b49\u3002\u80fd\u770b\u5230\u8fd9\u4e2a\u6a21\u5757\u63cf\u8ff0\uff1a\u6b64\u6a21\u5757\u5c06 AWS APIGateway \u4ee3\u7406\u8bf7\u6c42\u8f6c\u6362\u4e3a WSGI \u8bf7\u6c42\u3002<\/p>\n<pre><code>\"\"\" This module converts an AWS API Gateway proxied request to a WSGI request.   Inspired by: https:\/\/github.com\/miserlou\/zappa   Author: Logan Raarup &lt;[email&#160;protected]&gt; \"\"\" <\/code><\/pre>\n<p>\u8fd8\u662f\u76f8\u5f53\u6709\u610f\u601d\u7684\u3002<\/p>\n<h2>5. \u8fc1\u79fb LAB<\/h2>\n<p>\u63a5\u4e0b\u6765\u5c31\u5f97\u4e00\u70b9\u513f\u4e00\u70b9\u513f\u8fdb\u884c\u8fc1\u79fb\u4e86\uff0c\u4e0d\u96be\u60f3\u5230\u5e94\u8be5\u6709\u975e\u5e38\u591a\u7684\u5751\u7684\uff0c\u6bd4\u5982\u5982\u4f55\u8bbf\u95ee\u81ea\u5df1\u7684 MySQL \u3001Redis \u3001MongoDB\uff0c\u518d\u6bd4\u5982 Celery \u8ba1\u5212\u4efb\u52a1\uff0c\u81ea\u5df1\u662f\u7528 RabbitMQ \u7684\u6d88\u606f\u961f\u5217\uff0c\u8fd9\u4e1c\u897f\u8981\u600e\u4e48\u4e0a\u4e91\uff1f\u8fd9\u4e9b\u95ee\u9898\u90fd\u662f\u81ea\u5df1\u9700\u8981\u540e\u671f\u53bb\u89e3\u51b3\u7684\u3002\u6bd5\u7adf\u4e0a\u5927\u5b66\u5c31\u5f00\u59cb\u5199\u7684\u7f51\u7ad9\uff0c\u6709\u975e\u5e38\u975e\u5e38\u591a\u7684\u4f9d\u8d56\u2026\u2026<\/p>\n<p>\u66f4\u65b0\u65e5\u5fd7\uff1a\u5f53\u524d git \u7248\u672c\uff1a7a65018\uff0c\u603b\u63d0\u4ea4 824 \u6b21<\/p>\n<p>\u8fc1\u79fb\u6ce8\u5b9a\u662f\u4e00\u4e2a\u5927\u5de5\u7a0b\uff0c\u4e0b\u4e00\u7bc7\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fc1\u79fb\u9047\u5230\u7684\u5404\u79cd\u5751\u548c\u586b\u5751\u64cd\u4f5c\u3002<\/p>\n<blockquote>\n<p><strong>\u4f20\u9001\u95e8\uff1a<\/strong><\/p>\n<ul>\n<li>GitHub: github.com\/serverless<\/li>\n<li>\u5b98\u7f51\uff1aserverless.com<\/li>\n<li>\u793e\u533a\uff1aServerless \u4e2d\u6587\u7f51<\/li>\n<\/ul>\n<\/blockquote><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>0<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u5b9e\u9a8c\u5ba4\u7ad9\u8fc1\u79fb Serverless&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/88229"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=88229"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/88229\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=88229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=88229"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=88229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}