doc-exports/docs/fg/umn/functiongraph_04_0101.html
Chen, Junjie dac566cf2f FG UMN 20230725 version
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>
2024-04-03 10:30:56 +00:00

42 lines
7.2 KiB
HTML

<a name="functiongraph_04_0101"></a><a name="functiongraph_04_0101"></a>
<h1 class="topictitle1">Creating a Function from Scratch</h1>
<div id="body0000001297194441"><div class="section" id="functiongraph_04_0101__section2077511611339"><h4 class="sectiontitle">Introduction</h4><p id="functiongraph_04_0101__p129935814336">This section describes how to quickly create and test a HelloWorld function on the FunctionGraph console.</p>
</div>
<div class="section" id="functiongraph_04_0101__section0418520193311"><h4 class="sectiontitle">Step 1: Prepare the Environment</h4><p id="functiongraph_04_0101__p722313491535">To perform the operations described in this section, ensure that you have the <strong id="functiongraph_04_0101__b571115773214">FunctionGraph FullAccess</strong> permissions, that is, all permissions for FunctionGraph. For more information, see section "Permissions Management".</p>
</div>
<div class="section" id="functiongraph_04_0101__section2450193783315"><h4 class="sectiontitle">Step 2: Create a Function</h4><ol id="functiongraph_04_0101__ol1614414555101"><li id="functiongraph_04_0101__li7794535128">Log in to the FunctionGraph console. In the navigation pane, choose <strong id="functiongraph_04_0101__b18490724181815">Functions</strong> &gt; <strong id="functiongraph_04_0101__b134914247189">Function List</strong>.</li><li id="functiongraph_04_0101__li27941371211">Click <strong id="functiongraph_04_0101__b17311142317202">Create Function</strong> in the upper right corner and choose <strong id="functiongraph_04_0101__b143807309244">Create from scratch</strong>.</li><li id="functiongraph_04_0101__li12226824191318">On the displayed page, set <strong id="functiongraph_04_0101__b153426532114">Function Name</strong> to <strong id="functiongraph_04_0101__b757988122117">HelloWorld</strong>, retain the default values for other parameters, and click <strong id="functiongraph_04_0101__b9283171612110">Create Function</strong>. For details, see <a href="#functiongraph_04_0101__fig290685013818">Figure 1</a>.</li></ol>
<div class="fignone" id="functiongraph_04_0101__fig290685013818"><a name="functiongraph_04_0101__fig290685013818"></a><a name="fig290685013818"></a><span class="figcap"><b>Figure 1 </b>Configuring basic information</span><br><span><img id="functiongraph_04_0101__image19061950281" src="en-us_image_0000001679464913.png"></span></div>
<ol start="4" id="functiongraph_04_0101__ol1548345201514"><li id="functiongraph_04_0101__li548194510153">Configure the code source, copy the following code to the code window, and click <strong id="functiongraph_04_0101__b810914112217">Deploy</strong>.<div class="p" id="functiongraph_04_0101__p8880104813446">The sample code enables you to obtain test events and print test event information.<pre class="screen" id="functiongraph_04_0101__screen0178346114419">exports.handler = function (event, context, callback) {
const error = null;
const output = `Hello message: ${JSON.stringify(event)}`;
callback(error, output);
}</pre>
</div>
</li></ol>
</div>
<div class="section" id="functiongraph_04_0101__section1054774683313"><h4 class="sectiontitle">Step 3: Test the Function</h4><ol id="functiongraph_04_0101__ol138801929154513"><li id="functiongraph_04_0101__li118801429194518">On the function details page, click <strong id="functiongraph_04_0101__b19886205913217">Test</strong>. In the displayed dialog box, create a test event.</li><li id="functiongraph_04_0101__li1355343014466">Select <strong id="functiongraph_04_0101__b4461454191814">blank-template</strong>, set <strong id="functiongraph_04_0101__b856916620194">Event Name</strong> to <strong id="functiongraph_04_0101__b187021917198">test</strong>, modify the test event as follows, and click <strong id="functiongraph_04_0101__b13337151314192">Create</strong>.<pre class="screen" id="functiongraph_04_0101__screen77821922101">{
"hello": "function"
}</pre>
<div class="fignone" id="functiongraph_04_0101__fig1940722251517"><span class="figcap"><b>Figure 2 </b>Configuring a test event</span><br><span><img id="functiongraph_04_0101__image94071722101518" src="en-us_image_0000001631465770.png"></span></div>
</li></ol>
</div>
<div class="section" id="functiongraph_04_0101__section587765273314"><h4 class="sectiontitle">Step 4: View the Execution Result</h4><p id="functiongraph_04_0101__p552811143539">Click <strong id="functiongraph_04_0101__b17700193891519">Test</strong> and view the execution result on the right.</p>
<ul id="functiongraph_04_0101__ul1714875285210"><li id="functiongraph_04_0101__li20148952105216"><strong id="functiongraph_04_0101__b11407142313534">Function Output</strong>: displays the return result of the function.</li><li id="functiongraph_04_0101__li1659264116539"><strong id="functiongraph_04_0101__b9557132517531">Log Output</strong>: displays the execution logs of the function.</li><li id="functiongraph_04_0101__li1014811523528"><strong id="functiongraph_04_0101__b1766282416535">Summary</strong>: displays key information of the logs.<div class="fignone" id="functiongraph_04_0101__fig157061582522"><span class="figcap"><b>Figure 3 </b>Viewing the execution result</span><br><span><img id="functiongraph_04_0101__image1670668155211" src="en-us_image_0000001261803038.png"></span></div>
</li></ul>
<div class="note" id="functiongraph_04_0101__note1035002210544"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="functiongraph_04_0101__p1235012235414">A maximum of 2 KB logs can be displayed. For more log information, see section "Querying Function Logs".</p>
</div></div>
</div>
<div class="section" id="functiongraph_04_0101__section0486613514"><h4 class="sectiontitle">Step 5: View Monitoring Metrics</h4><p id="functiongraph_04_0101__p68574255014">On the function details page, click the <strong id="functiongraph_04_0101__b1337097146">Monitoring</strong> tab.</p>
<ul id="functiongraph_04_0101__ul514673445811"><li id="functiongraph_04_0101__li1814673415587">On the <strong id="functiongraph_04_0101__b152431737165312">Monitoring</strong> tab page, choose <strong id="functiongraph_04_0101__b17548418101316">Metrics</strong>, and select a time range (such as 5 minutes, 15 minutes, or 1 hour) to query the function.</li><li id="functiongraph_04_0101__li88981734907">The following metrics are displayed: invocations, errors, duration (including the maximum, average, and minimum durations), and throttles.</li></ul>
</div>
<div class="section" id="functiongraph_04_0101__section5661458145412"><h4 class="sectiontitle">Step 6: Delete a Function</h4><ol id="functiongraph_04_0101__ol07481824023"><li id="functiongraph_04_0101__li197481224129">On the function details page, choose <strong id="functiongraph_04_0101__b6137103021213">Operation</strong> &gt; <strong id="functiongraph_04_0101__b12443175210478">Delete Function</strong> in the upper right corner.</li><li id="functiongraph_04_0101__li0745531425">In the confirmation dialog box, enter <strong id="functiongraph_04_0101__b3374104583013">DELETE</strong> and click <strong id="functiongraph_04_0101__b179661748143013">OK</strong> to release resources in a timely manner.</li></ol>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="functiongraph_01_0505.html">Getting Started</a></div>
</div>
</div>