forked from docs/doc-exports
Reviewed-by: Eotvos, Oliver <oliver.eotvos@t-systems.com> Co-authored-by: Chen, Junjie <chenjunjie@huawei.com> Co-committed-by: Chen, Junjie <chenjunjie@huawei.com>
128 lines
20 KiB
HTML
128 lines
20 KiB
HTML
<a name="functiongraph_01_1441"></a><a name="functiongraph_01_1441"></a>
|
|
|
|
<h1 class="topictitle1">Creating an Event Function</h1>
|
|
<div id="body32001227"><div class="section" id="functiongraph_01_1441__en-us_topic_0000001251907924_section1532144210275"><h4 class="sectiontitle">Overview</h4><p id="functiongraph_01_1441__en-us_topic_0000001251907924_p1443142071918">A function is customized code for processing events. You can create a function from scratch and configure the function based on site requirements.</p>
|
|
<p id="functiongraph_01_1441__en-us_topic_0000001251907924_p3629253295320">FunctionGraph manages the compute resources required for function execution. After editing code for your function, configure compute resources on the FunctionGraph console.</p>
|
|
<p id="functiongraph_01_1441__en-us_topic_0000001251907924_p33932250193042">You can create a function from scratch or by using <a href="functiongraph_01_0401.html#functiongraph_01_0401">a template</a> or <a href="functiongraph_01_1047.html#functiongraph_01_1047">container image</a>.</p>
|
|
<div class="note" id="functiongraph_01_1441__en-us_topic_0000001251907924_note1022522017813"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="functiongraph_01_1441__en-us_topic_0000001251907924_p717314487720">When creating a function from scratch, configure the basic and code information based on <a href="#functiongraph_01_1441__en-us_topic_0000001251907924_table11741142114328">Table 1</a>. The parameters marked with an asterisk (*) are mandatory.</p>
|
|
<p id="functiongraph_01_1441__en-us_topic_0000001251907924_p14203186125115">Each FunctionGraph function runs in its own environment and has its own resources and file system.</p>
|
|
</div></div>
|
|
</div>
|
|
<div class="section" id="functiongraph_01_1441__en-us_topic_0000001251907924_section19689141182018"><h4 class="sectiontitle">Prerequisites</h4><ol id="functiongraph_01_1441__en-us_topic_0000001251907924_ol183175022018"><li id="functiongraph_01_1441__en-us_topic_0000001251907924_li0369141442419">You must be familiar with the programming languages supported by FunctionGraph. For details, see <a href="functiongraph_01_0151.html#functiongraph_01_0151">Supported Programming Languages</a>.</li><li id="functiongraph_01_1441__en-us_topic_0000001251907924_li18313504206">You have created a deployment package. For details, see <a href="functiongraph_01_0152.html#functiongraph_01_0152">Creating a Deployment Package</a>.</li><li id="functiongraph_01_1441__en-us_topic_0000001251907924_li92281811182117">(Optional) You have created an agency. For details, see <a href="functiongraph_01_0920.html#functiongraph_01_0920">Configuring Agency Permissions</a>.</li></ol>
|
|
</div>
|
|
<div class="section" id="functiongraph_01_1441__en-us_topic_0000001251907924_section139731612102810"><h4 class="sectiontitle">Procedure</h4><ol id="functiongraph_01_1441__en-us_topic_0000001251907924_ol149819304306"><li id="functiongraph_01_1441__en-us_topic_0000001251907924_li155710337386">Log in to the FunctionGraph console. In the navigation pane, choose <strong id="functiongraph_01_1441__en-us_topic_0000001251907924_b033610517502">Functions</strong> > <strong id="functiongraph_01_1441__en-us_topic_0000001251907924_b183361950502">Function List</strong>.</li><li id="functiongraph_01_1441__en-us_topic_0000001251907924_li1140195018364">On the <strong id="functiongraph_01_1441__en-us_topic_0000001251907924_b659423110517">Function List</strong> page, click <strong id="functiongraph_01_1441__en-us_topic_0000001251907924_b1594331155116">Create Function</strong> in the upper right corner.</li><li id="functiongraph_01_1441__en-us_topic_0000001251907924_li0466102917158">Click <strong id="functiongraph_01_1441__en-us_topic_0000001251907924_b153847753016">Create from scratch</strong> and configure the function information by referring to <a href="#functiongraph_01_1441__en-us_topic_0000001251907924_table11741142114328">Table 1</a>. The parameters marked with an asterisk (*) are mandatory.<div class="fignone" id="functiongraph_01_1441__en-us_topic_0000001251907924_fig8970133411132"><span class="figcap"><b>Figure 1 </b>Creating a function from scratch</span><br><span><img id="functiongraph_01_1441__en-us_topic_0000001251907924_image09715340136" src="en-us_image_0000001678732229.png"></span></div>
|
|
|
|
<div class="tablenoborder"><a name="functiongraph_01_1441__en-us_topic_0000001251907924_table11741142114328"></a><a name="en-us_topic_0000001251907924_table11741142114328"></a><table cellpadding="4" cellspacing="0" summary="" id="functiongraph_01_1441__en-us_topic_0000001251907924_table11741142114328" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Basic information</caption><thead align="left"><tr id="functiongraph_01_1441__en-us_topic_0000001251907924_row0741172163213"><th align="left" class="cellrowborder" valign="top" width="22.23%" id="mcps1.3.3.2.3.4.2.3.1.1"><p id="functiongraph_01_1441__en-us_topic_0000001251907924_p18741122133215">Parameter</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="77.77%" id="mcps1.3.3.2.3.4.2.3.1.2"><p id="functiongraph_01_1441__en-us_topic_0000001251907924_p474122113328">Description</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="functiongraph_01_1441__en-us_topic_0000001251907924_row174182193220"><td class="cellrowborder" valign="top" width="22.23%" headers="mcps1.3.3.2.3.4.2.3.1.1 "><p id="functiongraph_01_1441__en-us_topic_0000001251907924_p2741521153220">* Function Type</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="77.77%" headers="mcps1.3.3.2.3.4.2.3.1.2 "><ul id="functiongraph_01_1441__en-us_topic_0000001251907924_ul18742192143217"><li id="functiongraph_01_1441__en-us_topic_0000001251907924_li1774282119326">Event functions: triggered by triggers.</li><li id="functiongraph_01_1441__en-us_topic_0000001251907924_li674242111322">HTTP functions: triggered once HTTP requests are sent to specific URLs.<div class="note" id="functiongraph_01_1441__en-us_topic_0000001251907924_note474252111320"><span class="notetitle"> NOTE: </span><div class="notebody"><ul id="functiongraph_01_1441__en-us_topic_0000001251907924_ul1774272173213"><li id="functiongraph_01_1441__en-us_topic_0000001251907924_li19742192115326">HTTP functions do not distinguish between programming languages. The handler must be set in the <strong id="functiongraph_01_1441__en-us_topic_0000001251907924_b1340018410249">bootstrap</strong> file. You can directly write the startup command, and allow access over port 8000.</li><li id="functiongraph_01_1441__en-us_topic_0000001251907924_li14742221163211">HTTP functions support APIG and APIC triggers only.</li><li id="functiongraph_01_1441__en-us_topic_0000001251907924_li8742621203210">For details about how to use HTTP functions, see <a href="functiongraph_01_1442.html#functiongraph_01_1442">Creating an HTTP Function</a>.</li></ul>
|
|
</div></div>
|
|
</li></ul>
|
|
</td>
|
|
</tr>
|
|
<tr id="functiongraph_01_1441__en-us_topic_0000001251907924_row172206201017"><td class="cellrowborder" valign="top" width="22.23%" headers="mcps1.3.3.2.3.4.2.3.1.1 "><p id="functiongraph_01_1441__en-us_topic_0000001251907924_p142206201509">*Region</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="77.77%" headers="mcps1.3.3.2.3.4.2.3.1.2 "><p id="functiongraph_01_1441__en-us_topic_0000001251907924_p1122015201508">Select a region where you will deploy your code.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="functiongraph_01_1441__en-us_topic_0000001251907924_row1774262183216"><td class="cellrowborder" valign="top" width="22.23%" headers="mcps1.3.3.2.3.4.2.3.1.1 "><p id="functiongraph_01_1441__en-us_topic_0000001251907924_p674215214327">*Function Name</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="77.77%" headers="mcps1.3.3.2.3.4.2.3.1.2 "><p id="functiongraph_01_1441__en-us_topic_0000001251907924_p37421421143219">Name of the function, which must meet the following requirements:</p>
|
|
<ul id="functiongraph_01_1441__en-us_topic_0000001251907924_ul107421021143216"><li id="functiongraph_01_1441__en-us_topic_0000001251907924_li1374232143211">Consists of 1 to 60 characters, and can contain letters, digits, hyphens (-), and underscores (_).</li><li id="functiongraph_01_1441__en-us_topic_0000001251907924_li1574215214327">Starts with a letter and ends with a letter or digit.</li></ul>
|
|
</td>
|
|
</tr>
|
|
<tr id="functiongraph_01_1441__en-us_topic_0000001251907924_row6743132111329"><td class="cellrowborder" valign="top" width="22.23%" headers="mcps1.3.3.2.3.4.2.3.1.1 "><p id="functiongraph_01_1441__en-us_topic_0000001251907924_p18743112119325">Agency</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="77.77%" headers="mcps1.3.3.2.3.4.2.3.1.2 "><p id="functiongraph_01_1441__en-us_topic_0000001251907924_p774372111322">An agency is required if FunctionGraph accesses other cloud services. For details on how to create an agency, see <a href="functiongraph_01_0920.html#functiongraph_01_0920">Configuring Agency Permissions</a>.</p>
|
|
<p id="functiongraph_01_1441__en-us_topic_0000001251907924_p12743121153219">No agency is required if FunctionGraph does not access any cloud services.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="functiongraph_01_1441__en-us_topic_0000001251907924_row37431021143217"><td class="cellrowborder" valign="top" width="22.23%" headers="mcps1.3.3.2.3.4.2.3.1.1 "><p id="functiongraph_01_1441__en-us_topic_0000001251907924_p27439214327">*Enterprise Project</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="77.77%" headers="mcps1.3.3.2.3.4.2.3.1.2 "><p id="functiongraph_01_1441__en-us_topic_0000001251907924_p132443351451">Select a created enterprise project and add the function to it. By default, <strong id="functiongraph_01_1441__en-us_topic_0000001251907924_b153461443132010">default</strong> is selected.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="functiongraph_01_1441__en-us_topic_0000001251907924_row7353105614716"><td class="cellrowborder" valign="top" width="22.23%" headers="mcps1.3.3.2.3.4.2.3.1.1 "><p id="functiongraph_01_1441__en-us_topic_0000001251907924_p5354115613478">Runtime</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="77.77%" headers="mcps1.3.3.2.3.4.2.3.1.2 "><p id="functiongraph_01_1441__en-us_topic_0000001251907924_p63541256194717">Select a runtime to compile the function.</p>
|
|
<div class="notice" id="functiongraph_01_1441__en-us_topic_0000001251907924_note1274718429819"><span class="noticetitle"> NOTICE: </span><div class="noticebody"><p id="functiongraph_01_1441__en-us_topic_0000001251907924_p6747154213817">CloudIDE supports Node.js and Python only.</p>
|
|
</div></div>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</li><li id="functiongraph_01_1441__en-us_topic_0000001251907924_li19114457205018">Click <strong id="functiongraph_01_1441__en-us_topic_0000001251907924_b1482925015234">Create Function</strong>. On the displayed <strong id="functiongraph_01_1441__en-us_topic_0000001251907924_b104581325162414">Code</strong> tab page, continue to configure the code.</li></ol>
|
|
</div>
|
|
<div class="section" id="functiongraph_01_1441__en-us_topic_0000001251907924_section1655671712514"><h4 class="sectiontitle">Configuring Code</h4><ol id="functiongraph_01_1441__en-us_topic_0000001251907924_ol2903174882911"><li id="functiongraph_01_1441__en-us_topic_0000001251907924_li8436125292910">You can deploy the code based on the runtime you select. For details, see <a href="functiongraph_01_0152.html#functiongraph_01_0152">Creating a Deployment Package</a>. After the deployment is complete, click <strong id="functiongraph_01_1441__en-us_topic_0000001251907924_b3644514153719">Deploy</strong>.<p id="functiongraph_01_1441__en-us_topic_0000001251907924_p58269203212">As shown in the following example, to deploy code in Node.js 10.16, you can edit code inline, upload a local ZIP file, or upload a ZIP file from OBS.</p>
|
|
<div class="fignone" id="functiongraph_01_1441__en-us_topic_0000001251907924_fig14192511555"><span class="figcap"><b>Figure 2 </b>Deploying code</span><br><span><img id="functiongraph_01_1441__en-us_topic_0000001251907924_image2020105115517" src="en-us_image_0000001387236998.png"></span></div>
|
|
<div class="fignone" id="functiongraph_01_1441__en-us_topic_0000001251907924_fig15549051171915"><span class="figcap"><b>Figure 3 </b>Deploying code</span><br><span><img id="functiongraph_01_1441__en-us_topic_0000001251907924_image8549951171917" src="en-us_image_0000001630136520.png"></span></div>
|
|
</li><li id="functiongraph_01_1441__en-us_topic_0000001251907924_li3314123103115">You can modify the code and click <strong id="functiongraph_01_1441__en-us_topic_0000001251907924_b2015341034012">Deploy</strong> to deploy the code again.</li></ol>
|
|
</div>
|
|
<div class="section" id="functiongraph_01_1441__en-us_topic_0000001251907924_section124019932218"><h4 class="sectiontitle">Viewing Code Information</h4><ol id="functiongraph_01_1441__en-us_topic_0000001251907924_ol189974816240"><li id="functiongraph_01_1441__en-us_topic_0000001251907924_li989244811246">View code attributes.<p id="functiongraph_01_1441__en-us_topic_0000001251907924_p1589294814241"><a name="functiongraph_01_1441__en-us_topic_0000001251907924_li989244811246"></a><a name="en-us_topic_0000001251907924_li989244811246"></a>Code attributes show the code size and the time the code was modified.</p>
|
|
<div class="fignone" id="functiongraph_01_1441__en-us_topic_0000001251907924_fig2633638122312"><span class="figcap"><b>Figure 4 </b>Viewing code attributes</span><br><span><img id="functiongraph_01_1441__en-us_topic_0000001251907924_image156335384233" src="en-us_image_0000001629978216.png"></span></div>
|
|
</li><li id="functiongraph_01_1441__en-us_topic_0000001251907924_li108951485245">View basic information.<p id="functiongraph_01_1441__en-us_topic_0000001251907924_p17892048142411"><a name="functiongraph_01_1441__en-us_topic_0000001251907924_li108951485245"></a><a name="en-us_topic_0000001251907924_li108951485245"></a><a href="functiongraph_01_1828.html#functiongraph_01_1828">Configuring Basic Settings</a> shows the default memory and execution timeout in each runtime. You can click <strong id="functiongraph_01_1441__en-us_topic_0000001251907924_b33001125155216">Edit</strong> to switch to the <strong id="functiongraph_01_1441__en-us_topic_0000001251907924_b1223534455413">Basic Settings</strong> page and modify <strong id="functiongraph_01_1441__en-us_topic_0000001251907924_b129771317145413">Handler</strong>, <strong id="functiongraph_01_1441__en-us_topic_0000001251907924_b6923101525413">Memory (MB)</strong>, and <strong id="functiongraph_01_1441__en-us_topic_0000001251907924_b148491612165415">Execution Timeout (s)</strong> as required. For details, see <a href="#functiongraph_01_1441__en-us_topic_0000001251907924_fig11561614250">Figure 5</a>.</p>
|
|
<div class="fignone" id="functiongraph_01_1441__en-us_topic_0000001251907924_fig11561614250"><a name="functiongraph_01_1441__en-us_topic_0000001251907924_fig11561614250"></a><a name="en-us_topic_0000001251907924_fig11561614250"></a><span class="figcap"><b>Figure 5 </b>Editing basic information</span><br><span><img id="functiongraph_01_1441__en-us_topic_0000001251907924_image155621115250" src="en-us_image_0000001678858881.png"></span></div>
|
|
<p id="functiongraph_01_1441__en-us_topic_0000001251907924_p11375328714"></p>
|
|
<div class="notice" id="functiongraph_01_1441__en-us_topic_0000001251907924_note876417281919"><span class="noticetitle"><img src="public_sys-resources/notice_3.0-en-us.png"> </span><div class="noticebody"><p id="functiongraph_01_1441__en-us_topic_0000001251907924_p589254822410">Once a function is created, the runtime cannot be changed.</p>
|
|
</div></div>
|
|
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="functiongraph_01_1441__en-us_topic_0000001251907924_table19894164814248" frame="border" border="1" rules="all"><caption><b>Table 2 </b>Default basic information of each runtime</caption><thead align="left"><tr id="functiongraph_01_1441__en-us_topic_0000001251907924_row98931748112417"><th align="left" class="cellrowborder" valign="top" width="20.369999999999997%" id="mcps1.3.5.2.2.5.2.3.1.1"><p id="functiongraph_01_1441__en-us_topic_0000001251907924_p38921248182412">Runtime</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="79.63%" id="mcps1.3.5.2.2.5.2.3.1.2"><p id="functiongraph_01_1441__en-us_topic_0000001251907924_p1689224814245">Default Basic Information</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="functiongraph_01_1441__en-us_topic_0000001251907924_row08938481243"><td class="cellrowborder" valign="top" width="20.369999999999997%" headers="mcps1.3.5.2.2.5.2.3.1.1 "><p id="functiongraph_01_1441__en-us_topic_0000001251907924_p1089364819244">Java</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="79.63%" headers="mcps1.3.5.2.2.5.2.3.1.2 "><p id="functiongraph_01_1441__en-us_topic_0000001251907924_p158930488242">Memory (MB): 512</p>
|
|
<p id="functiongraph_01_1441__en-us_topic_0000001251907924_p15893448132417">Handler: com.demo.TriggerTests.apigTest</p>
|
|
<p id="functiongraph_01_1441__en-us_topic_0000001251907924_p48931548162416">Execution Timeout (s): 15</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="functiongraph_01_1441__en-us_topic_0000001251907924_row18893194815242"><td class="cellrowborder" valign="top" width="20.369999999999997%" headers="mcps1.3.5.2.2.5.2.3.1.1 "><p id="functiongraph_01_1441__en-us_topic_0000001251907924_p15893144810245">Node.js</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="79.63%" headers="mcps1.3.5.2.2.5.2.3.1.2 "><p id="functiongraph_01_1441__en-us_topic_0000001251907924_p1289311488248">Memory (MB): 128</p>
|
|
<p id="functiongraph_01_1441__en-us_topic_0000001251907924_p1089394813244">Handler: index.handler</p>
|
|
<p id="functiongraph_01_1441__en-us_topic_0000001251907924_p889314482242">Execution Timeout (s): 3</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="functiongraph_01_1441__en-us_topic_0000001251907924_row1089314819240"><td class="cellrowborder" valign="top" width="20.369999999999997%" headers="mcps1.3.5.2.2.5.2.3.1.1 "><p id="functiongraph_01_1441__en-us_topic_0000001251907924_p118931848182415">Custom</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="79.63%" headers="mcps1.3.5.2.2.5.2.3.1.2 "><p id="functiongraph_01_1441__en-us_topic_0000001251907924_p1589334802415">Memory (MB): 128</p>
|
|
<p id="functiongraph_01_1441__en-us_topic_0000001251907924_p989354812241">Handler: bootstrap</p>
|
|
<p id="functiongraph_01_1441__en-us_topic_0000001251907924_p1989354814249">Execution Timeout (s): 3</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="functiongraph_01_1441__en-us_topic_0000001251907924_row1988181022415"><td class="cellrowborder" valign="top" width="20.369999999999997%" headers="mcps1.3.5.2.2.5.2.3.1.1 "><p id="functiongraph_01_1441__en-us_topic_0000001251907924_p199881107245">Python</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="79.63%" headers="mcps1.3.5.2.2.5.2.3.1.2 "><p id="functiongraph_01_1441__en-us_topic_0000001251907924_p1463313942419">Memory (MB): 128</p>
|
|
<p id="functiongraph_01_1441__en-us_topic_0000001251907924_p963318394249">Handler: index.handler</p>
|
|
<p id="functiongraph_01_1441__en-us_topic_0000001251907924_p26331439162413">Execution Timeout (s): 3</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="functiongraph_01_1441__en-us_topic_0000001251907924_row92001364196"><td class="cellrowborder" valign="top" width="20.369999999999997%" headers="mcps1.3.5.2.2.5.2.3.1.1 "><p id="functiongraph_01_1441__en-us_topic_0000001251907924_p58261142101910">Go 1.x</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="79.63%" headers="mcps1.3.5.2.2.5.2.3.1.2 "><p id="functiongraph_01_1441__en-us_topic_0000001251907924_p1271114419198">Memory (MB): 128</p>
|
|
<p id="functiongraph_01_1441__en-us_topic_0000001251907924_p9271124420192">Handler: handler</p>
|
|
<p id="functiongraph_01_1441__en-us_topic_0000001251907924_p427111441196">Execution Timeout (s): 3</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</li></ol>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="functiongraph_01_0153.html">Creating a Function from Scratch</a></div>
|
|
</div>
|
|
</div>
|
|
|