forked from docs/doc-exports
Reviewed-by: Mützel, Andrea <andrea.muetzel@t-systems.com> Co-authored-by: liusiying01 <liusiying@huawei.com> Co-committed-by: liusiying01 <liusiying@huawei.com>
150 lines
25 KiB
HTML
150 lines
25 KiB
HTML
<a name="functiongraph_04_0104"></a><a name="functiongraph_04_0104"></a>
|
|
|
|
<h1 class="topictitle1">Creating an Event Function Using a Container Image and Executing the Function</h1>
|
|
<div id="body0000001422307556"><p id="functiongraph_04_0104__p4243144713415">This section uses the creation of an event function using a container image as an example to describe how to create and test a container image function.</p>
|
|
<p id="functiongraph_04_0104__p2073745323917">You need to implement an HTTP server in the image and listen to port <strong id="functiongraph_04_0104__b1857121816519">8000</strong> to receive requests. By default, the request path <strong id="functiongraph_04_0104__b647213120236">/init</strong> is the function initialization entry. Implement it as required. The request path <strong id="functiongraph_04_0104__b19710133922211">/invoke</strong> is the function execution entry where trigger events are processed. For details about request parameters, see section "Supported Event Sources". Note: You can use any base image.</p>
|
|
<div class="section" id="functiongraph_04_0104__section1397625114610"><h4 class="sectiontitle">Constraints</h4><ul id="functiongraph_04_0104__ul4475175110343"><li id="functiongraph_04_0104__li1475551163417">In the cloud environment, UID 1003 and GID 1003 are used to start the container by default. The two IDs can be modified by choosing <strong id="functiongraph_04_0104__b16677172282619">Configuration</strong> > <strong id="functiongraph_04_0104__b9677922112610">Basic Settings</strong> > <strong id="functiongraph_04_0104__b1467712224260">Container Image Override</strong> on the function details page. They cannot be <strong id="functiongraph_04_0104__b76771722162610">root</strong> or a reserved ID.</li><li id="functiongraph_04_0104__li14755517347">If the base image of the Alpine version is used, run the <strong id="functiongraph_04_0104__b1939782516264">addgroup</strong> and <strong id="functiongraph_04_0104__b53982257266">adduser</strong> commands.</li></ul>
|
|
</div>
|
|
<div class="section" id="functiongraph_04_0104__section0418520193311"><h4 class="sectiontitle">Prerequisites</h4><ol id="functiongraph_04_0104__functiongraph_04_0101_ol8106132642719"><li id="functiongraph_04_0104__functiongraph_04_0101_li4257144418303">Grant the FunctionGraph operation permissions to the user.<p id="functiongraph_04_0104__functiongraph_04_0101_p722313491535"><a name="functiongraph_04_0104__functiongraph_04_0101_li4257144418303"></a><a name="functiongraph_04_0101_li4257144418303"></a>To perform the operations described in this section, ensure that you have the <strong id="functiongraph_04_0104__functiongraph_04_0101_b14529817145619">FunctionGraph FullAccess</strong> permissions, that is, all permissions for FunctionGraph. For more information, see section <span class="uicontrol" id="functiongraph_04_0104__functiongraph_04_0101_uicontrol17648524536"><b>"Permissions Management"</b></span>.</p>
|
|
</li></ol>
|
|
</div>
|
|
<div class="section" id="functiongraph_04_0104__section992877392"><h4 class="sectiontitle">Step 1: Create an Image</h4><p id="functiongraph_04_0104__p068419143913">Take the Linux x86 64-bit OS as an example. (No system configuration is required.)</p>
|
|
</div>
|
|
<ol id="functiongraph_04_0104__ol4774141334018"><li id="functiongraph_04_0104__li977419139409">Create a folder.<pre class="screen" id="functiongraph_04_0104__screen3922727114118">mkdir custom_container_event_example && cd custom_container_event_example</pre>
|
|
</li></ol><ol start="2" id="functiongraph_04_0104__ol1390513210407"><li id="functiongraph_04_0104__li11905021164011">Implement an HTTP server to process <strong id="functiongraph_04_0104__b144811436195311">init</strong> and <strong id="functiongraph_04_0104__b15543183916537">invoke</strong> requests and give a response. Node.js is used as an example.<p id="functiongraph_04_0104__p187921276440">Create the <strong id="functiongraph_04_0104__b377835185420">main.js</strong> file to introduce the Express framework and implement a function handler (method <strong id="functiongraph_04_0104__b850093395512">POST</strong> and path <strong id="functiongraph_04_0104__b10103144195517">/invoke</strong> and an initializer (method <strong id="functiongraph_04_0104__b9765390561">POST</strong> and path <strong id="functiongraph_04_0104__b1797141720561">/init</strong>).</p>
|
|
<pre class="screen" id="functiongraph_04_0104__screen9377151661515">const express = require('express');
|
|
|
|
const PORT = 8000;
|
|
|
|
const app = express();
|
|
app.use(express.json());
|
|
|
|
app.post('/init', (req, res) => {
|
|
console.log('receive', req.body);
|
|
res.send('Hello init\n');
|
|
});
|
|
|
|
app.post('/invoke', (req, res) => {
|
|
console.log('receive', req.body);
|
|
res.send('Hello invoke\n');
|
|
});
|
|
|
|
app.listen(PORT, () => {
|
|
console.log(`Listening on http://localhost:${PORT}`);
|
|
});</pre>
|
|
</li></ol><ol start="3" id="functiongraph_04_0104__ol1035701334214"><li id="functiongraph_04_0104__li71011312114818">Create the <strong id="functiongraph_04_0104__b150788866233614">package.json</strong> file for npm so that it can identify the project and process project dependencies.<pre class="screen" id="functiongraph_04_0104__screen28121453164913">{
|
|
"name": "custom-container-event-example",
|
|
"version": "1.0.0",
|
|
"description": "An example of a custom container event function",
|
|
"main": "main.js",
|
|
"scripts": {},
|
|
"keywords": [],
|
|
"author": "",
|
|
"license": "ISC",
|
|
"dependencies": {
|
|
"express": "^4.17.1"
|
|
}
|
|
}</pre>
|
|
<ul id="functiongraph_04_0104__ul9401719516"><li id="functiongraph_04_0104__li144021105119"><strong id="functiongraph_04_0104__b120008991033618">name</strong>: project name</li><li id="functiongraph_04_0104__li1354861819513"><strong id="functiongraph_04_0104__b172019169533620">version</strong>: project version</li><li id="functiongraph_04_0104__li71791629115113"><strong id="functiongraph_04_0104__b49431857152852">main</strong>: application entry file</li><li id="functiongraph_04_0104__li3728104885115"><strong id="functiongraph_04_0104__b7950572633632">dependencies</strong>: all available dependencies of the project in npm</li></ul>
|
|
</li><li id="functiongraph_04_0104__li5357613144220">Create a Dockerfile.<pre class="screen" id="functiongraph_04_0104__screen01586461643">FROM node:12.10.0
|
|
|
|
ENV HOME=/home/custom_container
|
|
ENV <strong id="functiongraph_04_0104__b1737554184718">GROUP_ID</strong>=<strong id="functiongraph_04_0104__b2861171164716">1003</strong>
|
|
ENV GROUP_NAME=custom_container
|
|
ENV <strong id="functiongraph_04_0104__b671848154711">USER_ID</strong>=<strong id="functiongraph_04_0104__b686915194714">1003</strong>
|
|
ENV USER_NAME=custom_container
|
|
|
|
RUN mkdir -m 550 ${HOME} && groupadd -g ${GROUP_ID} ${GROUP_NAME} && useradd -u ${USER_ID} -g ${GROUP_ID} ${USER_NAME}
|
|
|
|
COPY --chown=${USER_ID}:${GROUP_ID} main.js ${HOME}
|
|
COPY --chown=${USER_ID}:${GROUP_ID} package.json ${HOME}
|
|
|
|
RUN cd ${HOME} && npm install
|
|
|
|
RUN chown -R ${USER_ID}:${GROUP_ID} ${HOME}
|
|
|
|
RUN find ${HOME} -type d | xargs chmod 500
|
|
RUN find ${HOME} -type f | xargs chmod 500
|
|
|
|
USER ${USER_NAME}
|
|
WORKDIR ${HOME}
|
|
|
|
EXPOSE 8000
|
|
ENTRYPOINT ["node", "/home/custom_container/main.js"]</pre>
|
|
<ul id="functiongraph_04_0104__ul10963114434217"><li id="functiongraph_04_0104__li29636447427"><strong id="functiongraph_04_0104__b40866829433755">FROM</strong>: Specify base image <strong id="functiongraph_04_0104__b64439147333755">node:12.10.0</strong>. The base image is mandatory and its value can be changed.</li><li id="functiongraph_04_0104__li137654248557"><strong id="functiongraph_04_0104__b1837823595111">ENV</strong>: Set environment variables <strong id="functiongraph_04_0104__b1037919351511">HOME</strong> (<strong id="functiongraph_04_0104__b16379113575119">/home/custom_container</strong>), <strong id="functiongraph_04_0104__b5379103511512">GROUP_NAME</strong> and <strong id="functiongraph_04_0104__b13806353510">USER_NAME</strong> (<strong id="functiongraph_04_0104__b138053520516">custom_container</strong>), <strong id="functiongraph_04_0104__b43811635205116">USER_ID</strong> and <strong id="functiongraph_04_0104__b938193575114">GROUP_ID</strong> (<strong id="functiongraph_04_0104__b1238114352513">1003</strong>). These environment variables are mandatory and their values can be changed.</li><li id="functiongraph_04_0104__li198492020124718"><strong id="functiongraph_04_0104__b109092800833831">RUN</strong>: Use the format <strong id="functiongraph_04_0104__b208547321533831">RUN</strong> <em id="functiongraph_04_0104__i197117224133831"><Command></em>. For example, <strong id="functiongraph_04_0104__b187155336233831">RUN mkdir -m 550 ${HOME}</strong>, which means to create the <strong id="functiongraph_04_0104__b52161570233831">home</strong> directory for user <em id="functiongraph_04_0104__i21948652033831">${USER_NAME}</em> during container building.</li><li id="functiongraph_04_0104__li15560499126"><strong id="functiongraph_04_0104__b110717632633834">USER</strong>: Switch to user <em id="functiongraph_04_0104__i214655775933834">${USER_NAME}</em>.</li><li id="functiongraph_04_0104__li1573427151310"><strong id="functiongraph_04_0104__b84661387513">WORKDIR</strong>: Switch the working directory to the <strong id="functiongraph_04_0104__b84661638165115">${HOME}</strong> directory of user <em id="functiongraph_04_0104__i74662385517">${USER_NAME}</em>.</li><li id="functiongraph_04_0104__li11176163481315"><strong id="functiongraph_04_0104__b183528929333848">COPY</strong>: Copy <strong id="functiongraph_04_0104__b137164894733848">main.js</strong> and <strong id="functiongraph_04_0104__b209721228533848">package.json</strong> to the <strong id="functiongraph_04_0104__b122061061533848">home</strong> directory of user <em id="functiongraph_04_0104__i12137363233848">${USER_NAME}</em> in the container.</li><li id="functiongraph_04_0104__li19963544104216"><strong id="functiongraph_04_0104__b166557212833858">EXPOSE</strong>: Expose port 8000 of the container. Do not change this parameter.</li><li id="functiongraph_04_0104__li1799418920148"><strong id="functiongraph_04_0104__b1762714115267">ENTRYPOINT</strong>: Run the <strong id="functiongraph_04_0104__b156281511261">node /home/tester/main.js</strong> command to start the container.</li></ul>
|
|
</li></ol><ol start="5" id="functiongraph_04_0104__ol12590173254310"><li id="functiongraph_04_0104__li65901932114317">Build an image.<p id="functiongraph_04_0104__p8688195019499"><a name="functiongraph_04_0104__li65901932114317"></a><a name="li65901932114317"></a>In the following example, the image name is <strong id="functiongraph_04_0104__b051184212266">custom_container_event_example</strong>, the tag is <strong id="functiongraph_04_0104__b165294222611">latest</strong>, and the period (.) indicates the directory where the Dockerfile is located. Run the image build command to pack all files in the directory and send the package to a container engine to build an image.</p>
|
|
<pre class="screen" id="functiongraph_04_0104__screen1356617348547">docker build -t custom_container_event_example:latest .</pre>
|
|
</li></ol>
|
|
<div class="section" id="functiongraph_04_0104__section14706131145612"><h4 class="sectiontitle">Step 2: Perform Local Verification</h4><ol id="functiongraph_04_0104__ol15219131615717"><li id="functiongraph_04_0104__li19219171614578">Start the Docker container.<pre class="screen" id="functiongraph_04_0104__screen32034014570">docker run -u 1003:1003 -p 8000:8000 custom_container_event_example:latest</pre>
|
|
</li></ol><ol start="2" id="functiongraph_04_0104__ol3221850579"><li id="functiongraph_04_0104__li32212511577">Open a new Command Prompt, and send a message through port 8000 to access the <strong id="functiongraph_04_0104__b2828124173020">/init</strong> directory specified in the template code.<pre class="screen" id="functiongraph_04_0104__screen207121444175712">curl -XPOST -H 'Content-Type: application/json' localhost:8000/init</pre>
|
|
<p id="functiongraph_04_0104__p11235659183714">The following information is returned based on the module code:</p>
|
|
<pre class="screen" id="functiongraph_04_0104__screen1265281710582">Hello init</pre>
|
|
</li></ol><ol start="3" id="functiongraph_04_0104__ol22512286217"><li id="functiongraph_04_0104__li15251132812117">Open a new Command Prompt, and send a message through port 8000 to access the <strong id="functiongraph_04_0104__b811172233012">/invoke</strong> directory specified in the template code.<pre class="screen" id="functiongraph_04_0104__screen124071828202015">curl -XPOST -H 'Content-Type: application/json' -d '{"message":"HelloWorld"}' localhost:8000/invoke</pre>
|
|
<p id="functiongraph_04_0104__p20629115182118">The following information is returned based on the module code:</p>
|
|
<pre class="screen" id="functiongraph_04_0104__screen186297572112">Hello invoke</pre>
|
|
</li></ol><ol start="4" id="functiongraph_04_0104__ol9502356212"><li id="functiongraph_04_0104__li191694822117">Check whether the following information is displayed:<pre class="screen" id="functiongraph_04_0104__screen671035515211">Listening on http://localhost:8000
|
|
receive {}
|
|
receive { message: 'HelloWorld' }</pre>
|
|
<p id="functiongraph_04_0104__p1969310287228"><span><img id="functiongraph_04_0104__image196921228112216" src="en-us_image_0000001472598601.png" title="Click to enlarge" class="imgResize"></span></p>
|
|
<p id="functiongraph_04_0104__p15809135251513">Alternatively, run the <strong id="functiongraph_04_0104__b72862116733928">docker logs</strong> command to obtain container logs.</p>
|
|
<p id="functiongraph_04_0104__p2281115163"><span><img id="functiongraph_04_0104__image191981812181620" src="en-us_image_0000001472598777.png" title="Click to enlarge" class="imgResize"></span></p>
|
|
</li></ol>
|
|
</div>
|
|
<div class="section" id="functiongraph_04_0104__section15137197135915"><h4 class="sectiontitle">Step 3: Upload the Image</h4><ol id="functiongraph_04_0104__ol10526155517598"><li id="functiongraph_04_0104__li1280144911552">Log in to the SWR console. In the navigation pane, choose <strong id="functiongraph_04_0104__b13947731193020">My Images</strong>.</li><li id="functiongraph_04_0104__li19526145511590">Click <strong id="functiongraph_04_0104__b1692611332300">Upload Through Client</strong> or <strong id="functiongraph_04_0104__b15926633133010">Upload Through SWR</strong> in the upper right corner.</li><li id="functiongraph_04_0104__li1169192171917">Upload the image as prompted.<p id="functiongraph_04_0104__p87902033161813"><a name="functiongraph_04_0104__li1169192171917"></a><a name="li1169192171917"></a></p>
|
|
<p id="functiongraph_04_0104__p114152117338"><span><img id="functiongraph_04_0104__image9415611113316" src="en-us_image_0000001630990134.png" title="Click to enlarge" class="imgResize"></span></p>
|
|
<p id="functiongraph_04_0104__p8491165512019"></p>
|
|
</li><li id="functiongraph_04_0104__li823013951820">View the image on the <strong id="functiongraph_04_0104__b14941115153019">My Images</strong> page.</li></ol>
|
|
</div>
|
|
<div class="section" id="functiongraph_04_0104__section12330203912578"><h4 class="sectiontitle">Step 4: Create a Function</h4><ol id="functiongraph_04_0104__ol18740710529"><li id="functiongraph_04_0104__li7794535128">In the left navigation pane of the management console, choose <strong id="functiongraph_04_0104__b1931210291267">Compute</strong> > <strong id="functiongraph_04_0104__b11312029192619">FunctionGraph</strong>. On the FunctionGraph console, choose <strong id="functiongraph_04_0104__b12977753429565">Functions</strong> > <strong id="functiongraph_04_0104__b6862851479565">Function List</strong> from the navigation pane.</li><li id="functiongraph_04_0104__li27941371211">Click <strong id="functiongraph_04_0104__b16132039132110">Create Function</strong> in the upper right corner. On the displayed page, select <strong id="functiongraph_04_0104__b51413395217">Container Image</strong> for creation mode.</li><li id="functiongraph_04_0104__li1176013361624">Set the basic function information.<ul id="functiongraph_04_0104__ul1714016229416"><li id="functiongraph_04_0104__li9143162215418"><strong id="functiongraph_04_0104__b10930105125113">Function Type</strong>: Select <strong id="functiongraph_04_0104__b189301151115117">Event Function</strong>.</li><li id="functiongraph_04_0104__li183851018175617"><strong id="functiongraph_04_0104__b799316560510">Region</strong>: The default value is used. You can select other regions.<p id="functiongraph_04_0104__p187181138134519"><strong id="functiongraph_04_0104__b13928443162113">Regions are geographic areas isolated from each other. Resources are region-specific and cannot be used across regions through internal network connections. For low network latency and quick resource access, select the nearest region.</strong></p>
|
|
</li><li id="functiongraph_04_0104__li5121204615412"><strong id="functiongraph_04_0104__b83812483210">Function Name</strong>: Enter <strong id="functiongraph_04_0104__b1381948132119">custom_container_http</strong>.</li><li id="functiongraph_04_0104__li1818413119017"><strong id="functiongraph_04_0104__b8979815145218">Enterprise Project</strong>: The default value is <strong id="functiongraph_04_0104__b13979515155215">default</strong>. You can select the created enterprise project.<p id="functiongraph_04_0104__p167241052144512">Enterprise projects let you manage cloud resources and users by project.</p>
|
|
</li><li id="functiongraph_04_0104__li39981317382"><strong id="functiongraph_04_0104__b1758875852112">Agency</strong>: Select an agency with the <strong id="functiongraph_04_0104__b258813586217">SWR Admin</strong> permission. If no agency is available, create one by referring to <a href="functiongraph_01_0920.html">Creating an Agency</a>.</li><li id="functiongraph_04_0104__li11250348182118"><strong id="functiongraph_04_0104__b1854714414222">Container Image</strong>: Enter the image uploaded to SWR in <a href="functiongraph_04_0103.html#functiongraph_04_0103__section15137197135915">step 3</a>. </li></ul>
|
|
</li><li id="functiongraph_04_0104__li1653311367119">(Optional) Set container image overriding parameters.<ul id="functiongraph_04_0104__ul65371241215"><li id="functiongraph_04_0104__li17537342212"><strong id="functiongraph_04_0104__b1980212252527">CMD</strong>: container startup command. Example: <strong id="functiongraph_04_0104__b1180292510523">/bin/sh</strong>. If no command is specified, the entrypoint or CMD in the image configuration will be used.</li><li id="functiongraph_04_0104__li64161535522"><strong id="functiongraph_04_0104__b154745322521">Args</strong>: container startup parameter. Example: <strong id="functiongraph_04_0104__b15474332185220">-args,value1</strong>. If no argument is specified, CMD in the image configuration will be used.</li><li id="functiongraph_04_0104__li189425262420"><strong id="functiongraph_04_0104__b2179193612223">Working Dir</strong>: working directory where a container runs. If no directory is specified, the directory in the image configuration will be used. The directory must start with a slash (/).</li><li id="functiongraph_04_0104__li7878121119311"><strong id="functiongraph_04_0104__b82521738175220">User ID</strong>: Enter the user ID.</li><li id="functiongraph_04_0104__li167132024434"><strong id="functiongraph_04_0104__b1425112419522">Group ID</strong>: Enter the user group ID.</li></ul>
|
|
</li><li id="functiongraph_04_0104__li15142169181415"><strong id="functiongraph_04_0104__functiongraph_04_0101_b138464532075">Advanced Settings</strong>: <strong id="functiongraph_04_0104__functiongraph_04_0101_b177989591277">Collect Logs</strong> is disabled by default. If it is enabled, function execution logs will be reported to Log Tank Service (LTS). You will be billed for log management on a pay-per-use basis.
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="functiongraph_04_0104__functiongraph_04_0101_table586619443117" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Parameters for configuring Collect Logs</caption><thead align="left"><tr id="functiongraph_04_0104__functiongraph_04_0101_row686618443112"><th align="left" class="cellrowborder" valign="top" width="32.31%" id="mcps1.3.12.2.5.3.2.3.1.1"><p id="functiongraph_04_0104__functiongraph_04_0101_p14866749313">Parameter</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="67.69%" id="mcps1.3.12.2.5.3.2.3.1.2"><p id="functiongraph_04_0104__functiongraph_04_0101_p178668423117">Description</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="functiongraph_04_0104__functiongraph_04_0101_row1886615419311"><td class="cellrowborder" valign="top" width="32.31%" headers="mcps1.3.12.2.5.3.2.3.1.1 "><p id="functiongraph_04_0104__functiongraph_04_0101_p11866144103115">Log Configuration</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="67.69%" headers="mcps1.3.12.2.5.3.2.3.1.2 "><p id="functiongraph_04_0104__functiongraph_04_0101_p1886610493115">You can select <strong id="functiongraph_04_0104__functiongraph_04_0101_b1757312367911">Auto</strong> or <strong id="functiongraph_04_0104__functiongraph_04_0101_b134872038395">Custom</strong>.</p>
|
|
<ul id="functiongraph_04_0104__functiongraph_04_0101_ul894114313424"><li id="functiongraph_04_0104__functiongraph_04_0101_li13941539425"><strong id="functiongraph_04_0104__functiongraph_04_0101_b8972558161013">Auto</strong>: Use the default log group and log stream. Log groups prefixed with "functiongraph.log.group" are filtered out.</li><li id="functiongraph_04_0104__functiongraph_04_0101_li1713036164219"><strong id="functiongraph_04_0104__functiongraph_04_0101_b15597122141115">Custom</strong>: Select a custom log group and log stream. Log streams that are in the same enterprise project as your function.</li></ul>
|
|
</td>
|
|
</tr>
|
|
<tr id="functiongraph_04_0104__functiongraph_04_0101_row1386618412312"><td class="cellrowborder" valign="top" width="32.31%" headers="mcps1.3.12.2.5.3.2.3.1.1 "><p id="functiongraph_04_0104__functiongraph_04_0101_p286619414315">Log Tag</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="67.69%" headers="mcps1.3.12.2.5.3.2.3.1.2 "><p id="functiongraph_04_0104__functiongraph_04_0101_p138661483113">You can use these tags to filter function logs in LTS. You can add 10 more tags.</p>
|
|
<p id="functiongraph_04_0104__functiongraph_04_0101_p144926153617">Tag key/value: Enter a maximum of 64 characters. Only digits, letters, underscores (_), and hyphens (-) are allowed.</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</li><li id="functiongraph_04_0104__li1416383714911">After the configuration is complete, click <strong id="functiongraph_04_0104__b10629132853113">Create Function</strong>.</li><li id="functiongraph_04_0104__li10240122622416">On the function details page, choose <strong id="functiongraph_04_0104__b1758141715325">Configuration</strong> > <strong id="functiongraph_04_0104__b10200921173217">Lifecycle</strong>, and enable <strong id="functiongraph_04_0104__b5186183113324">Initialization</strong>. The <strong id="functiongraph_04_0104__b1068916486321">init</strong> API will be called to initialize the function.</li></ol>
|
|
</div>
|
|
<div class="section" id="functiongraph_04_0104__section623165141019"><h4 class="sectiontitle">Step 5: Test the Function</h4><ol id="functiongraph_04_0104__ol138801929154513"><li id="functiongraph_04_0104__li118801429194518">On the function details page, click <strong id="functiongraph_04_0104__b8564826193320">Test</strong>. In the displayed dialog box, create a test event.</li><li id="functiongraph_04_0104__li1355343014466">Select <strong id="functiongraph_04_0104__b1628082933310">blank-template</strong>, set <strong id="functiongraph_04_0104__b6280162943315">Event Name</strong> to <strong id="functiongraph_04_0104__b16280129113313">helloworld</strong>, modify the test event as follows, and click <strong id="functiongraph_04_0104__b728182915334">Create</strong>.<pre class="screen" id="functiongraph_04_0104__screen4222153532514">{
|
|
"message": "HelloWorld"
|
|
}</pre>
|
|
</li></ol>
|
|
</div>
|
|
<div class="section" id="functiongraph_04_0104__section109701256191214"><h4 class="sectiontitle">Step 6: View the Execution Result</h4><p id="functiongraph_04_0104__p852616631310">Click <strong id="functiongraph_04_0104__b1163404011330">Test</strong> and view the execution result on the right.</p>
|
|
<div class="fignone" id="functiongraph_04_0104__fig19835131516462"><span class="figcap"><b>Figure 1 </b>Execution result</span><br><span><img id="functiongraph_04_0104__image18836191584614" src="en-us_image_0000001422840354.png" title="Click to enlarge" class="imgResize"></span></div>
|
|
<ul id="functiongraph_04_0104__ul1714875285210"><li id="functiongraph_04_0104__li20148952105216"><strong id="functiongraph_04_0104__b69861346133320">Function Output</strong>: displays the return result of the function.</li><li id="functiongraph_04_0104__li1659264116539"><strong id="functiongraph_04_0104__b21755118333">Log Output</strong>: displays the execution logs of the function.</li><li id="functiongraph_04_0104__li1014811523528"><strong id="functiongraph_04_0104__b8331854173313">Summary</strong>: displays key information of the logs.<div class="note" id="functiongraph_04_0104__note153221935131416"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="functiongraph_04_0104__functiongraph_04_0101_p1235012235414">A maximum of 2 KB logs can be displayed. For more log information, see <a href="functiongraph_01_0170.html">Querying Function Logs</a>.</p>
|
|
</div></div>
|
|
</li></ul>
|
|
</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>
|
|
|
|
|
|
<script language="JavaScript">
|
|
<!--
|
|
image_size('.imgResize');
|
|
var msg_imageMax = "view original image";
|
|
var msg_imageClose = "close";
|
|
//--></script> |