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>
135 lines
25 KiB
HTML
135 lines
25 KiB
HTML
<a name="functiongraph_01_1047"></a><a name="functiongraph_01_1047"></a>
|
|
|
|
<h1 class="topictitle1">Creating a Function with an Image</h1>
|
|
<div id="body8662426"><div class="section" id="functiongraph_01_1047__en-us_topic_0000001298667445_section11281162684319"><h4 class="sectiontitle">Introduction</h4><p id="functiongraph_01_1047__en-us_topic_0000001298667445_p133229587281">Package your container images complying with the Open Container Initiative (OCI) standard, and upload them to FunctionGraph. The images will be loaded and run by FunctionGraph. Unlike the code upload mode, you can use a custom code package, which is flexible and reduces migration costs. You can create event and HTTP functions by using a custom image.</p>
|
|
<p id="functiongraph_01_1047__en-us_topic_0000001298667445_p144081946111019">For details about how to develop and deploy an HTTP function using a container image, see <a href="functiongraph_04_0103.html">Developing an HTTP Function</a>.</p>
|
|
<p id="functiongraph_01_1047__en-us_topic_0000001298667445_p10521125162810">For details about how to develop and deploy an event function using a container image, see <a href="functiongraph_04_0104.html">Creating an Event Function Using a Container Image and Executing the Function</a>.</p>
|
|
<div class="p" id="functiongraph_01_1047__en-us_topic_0000001298667445_p14413174110716">The following features are supported:<ul id="functiongraph_01_1047__en-us_topic_0000001298667445_ul1014620123414"><li id="functiongraph_01_1047__en-us_topic_0000001298667445_li191418203348"><strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b161132103520">Downloading images</strong><p id="functiongraph_01_1047__en-us_topic_0000001298667445_p55351850105213">Images are stored in SoftWare Repository for Container (SWR) and can only be downloaded by users with the <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b912369164218">SWR Admin</strong> permission. FunctionGraph will call the SWR API to generate and set temporary login commands before creating instances.</p>
|
|
</li></ul>
|
|
<ul id="functiongraph_01_1047__en-us_topic_0000001298667445_ul18282195091313"><li id="functiongraph_01_1047__en-us_topic_0000001298667445_li918794653413"><strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b1146644818397">Setting environment variables</strong><p id="functiongraph_01_1047__en-us_topic_0000001298667445_p198712364017">Encryption settings and environment variables are supported. For details, see <a href="functiongraph_01_0154.html#functiongraph_01_0154">Configuring Environment Variables</a>.</p>
|
|
</li><li id="functiongraph_01_1047__en-us_topic_0000001298667445_li4488153013512"><strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b15427191519409">Attaching external data disks</strong><p id="functiongraph_01_1047__en-us_topic_0000001298667445_p1112717418582">External data disks can be attached. For details, see <a href="functiongraph_01_0402.html#functiongraph_01_0402">Configuring Disk Mounting</a>.</p>
|
|
</li><li id="functiongraph_01_1047__en-us_topic_0000001298667445_li1187872116363"><strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b183789149397">Reserved instances</strong><p id="functiongraph_01_1047__en-us_topic_0000001298667445_p96162317366">For details, see the description about reserved instances.</p>
|
|
</li><li id="functiongraph_01_1047__en-us_topic_0000001298667445_li13931451173111"><strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b17306143019273">Deploying a new image</strong><p id="functiongraph_01_1047__en-us_topic_0000001298667445_p172166493313">You can redeploy a new image in a function.</p>
|
|
</li></ul>
|
|
<div class="note" id="functiongraph_01_1047__en-us_topic_0000001298667445_note119572599358"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="functiongraph_01_1047__en-us_topic_0000001298667445_p1170810123618">User containers will be started using UID 1003 and GID 1003, which are the same as other types of functions.</p>
|
|
</div></div>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="functiongraph_01_1047__en-us_topic_0000001298667445_section313719675517"><h4 class="sectiontitle">Prerequisites</h4><p id="functiongraph_01_1047__en-us_topic_0000001298667445_p4726163318108">You have created an agency with the <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b5902528173816">SWR Admin</strong> permission by referring to <a href="functiongraph_01_0920.html#functiongraph_01_0920">Configuring Agency Permissions</a>. Images are stored in SWR, and only users with this permission can invoke and pull images.</p>
|
|
</div>
|
|
<div class="section" id="functiongraph_01_1047__en-us_topic_0000001298667445_section29749266282"><h4 class="sectiontitle">Procedure</h4><ol id="functiongraph_01_1047__en-us_topic_0000001298667445_ol1758316312454"><li id="functiongraph_01_1047__en-us_topic_0000001298667445_li175831331114511">Log in to the FunctionGraph console. In the navigation pane, choose <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_en-us_topic_0000001251907924_b033610517502">Functions</strong> > <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_en-us_topic_0000001251907924_b183361950502">Function List</strong>.</li><li id="functiongraph_01_1047__en-us_topic_0000001298667445_li1661111214614">On the <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_en-us_topic_0000001251907924_b659423110517">Function List</strong> page, click <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_en-us_topic_0000001251907924_b1594331155116">Create Function</strong> in the upper right corner.</li><li id="functiongraph_01_1047__en-us_topic_0000001298667445_li1040883174617">Select <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b20561730205112">Container Image</strong>. For details, see <a href="#functiongraph_01_1047__en-us_topic_0000001298667445_table6474815173514">Table 1</a>.<div class="fignone" id="functiongraph_01_1047__en-us_topic_0000001298667445_fig10875142222416"><span class="figcap"><b>Figure 1 </b>Creating a function using a container image</span><br><span><img id="functiongraph_01_1047__en-us_topic_0000001298667445_image1087513229245" src="en-us_image_0000001678918577.png" title="Click to enlarge" class="imgResize"></span></div>
|
|
|
|
<div class="tablenoborder"><a name="functiongraph_01_1047__en-us_topic_0000001298667445_table6474815173514"></a><a name="en-us_topic_0000001298667445_table6474815173514"></a><table cellpadding="4" cellspacing="0" summary="" id="functiongraph_01_1047__en-us_topic_0000001298667445_table6474815173514" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Parameter description</caption><thead align="left"><tr id="functiongraph_01_1047__en-us_topic_0000001298667445_row5472191543516"><th align="left" class="cellrowborder" valign="top" width="15.85%" id="mcps1.3.3.2.3.4.2.3.1.1"><p id="functiongraph_01_1047__en-us_topic_0000001298667445_p164721153356">Parameter</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="84.15%" id="mcps1.3.3.2.3.4.2.3.1.2"><p id="functiongraph_01_1047__en-us_topic_0000001298667445_p15472101511350">Description</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="functiongraph_01_1047__en-us_topic_0000001298667445_row647351523510"><td class="cellrowborder" valign="top" width="15.85%" headers="mcps1.3.3.2.3.4.2.3.1.1 "><p id="functiongraph_01_1047__en-us_topic_0000001298667445_p9472111511353">*Function Type</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="84.15%" headers="mcps1.3.3.2.3.4.2.3.1.2 "><p id="functiongraph_01_1047__en-us_topic_0000001298667445_p1647214157351">Select a function type.</p>
|
|
<p id="functiongraph_01_1047__en-us_topic_0000001298667445_p09118461423"></p>
|
|
<div class="p" id="functiongraph_01_1047__en-us_topic_0000001298667445_p107946498428"><strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b18170610111416">HTTP function</strong>: triggered once HTTP requests are sent to specific URLs.<div class="note" id="functiongraph_01_1047__en-us_topic_0000001298667445_note124731415103518"><span class="notetitle"> NOTE: </span><div class="notebody"><ul id="functiongraph_01_1047__en-us_topic_0000001298667445_ul144729151351"><li id="functiongraph_01_1047__en-us_topic_0000001298667445_li1046744915279">The custom container image must contain an HTTP server with listening port 8000.</li><li id="functiongraph_01_1047__en-us_topic_0000001298667445_li164721615183514">HTTP functions support APIG triggers only.</li><li id="functiongraph_01_1047__en-us_topic_0000001298667445_li1839714919261">When calling a function using APIG, <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b1654014294510">isBase64Encoded</strong> is valued <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b185401298519">true</strong> by default, indicating that the request body transferred to FunctionGraph is encoded using Base64 and must be decoded for processing.</li><li id="functiongraph_01_1047__en-us_topic_0000001298667445_li1574044172716">The function must return characters strings by using the following structure.<pre class="screen" id="functiongraph_01_1047__en-us_topic_0000001298667445_screen2028202712279">{
|
|
"isBase64Encoded": true|false,
|
|
"statusCode": httpStatusCode,
|
|
"headers": {"headerName":"headerValue",...},
|
|
"body": "..."
|
|
}</pre>
|
|
</li></ul>
|
|
</div></div>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<tr id="functiongraph_01_1047__en-us_topic_0000001298667445_row4575184013157"><td class="cellrowborder" valign="top" width="15.85%" headers="mcps1.3.3.2.3.4.2.3.1.1 "><p id="functiongraph_01_1047__en-us_topic_0000001298667445_p85751740121512">*Region</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="84.15%" headers="mcps1.3.3.2.3.4.2.3.1.2 "><p id="functiongraph_01_1047__en-us_topic_0000001298667445_p3575740181519">Select a region where you will deploy your code.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="functiongraph_01_1047__en-us_topic_0000001298667445_row047391510352"><td class="cellrowborder" valign="top" width="15.85%" headers="mcps1.3.3.2.3.4.2.3.1.1 "><p id="functiongraph_01_1047__en-us_topic_0000001298667445_p16473315153517">*Function Name</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="84.15%" headers="mcps1.3.3.2.3.4.2.3.1.2 "><p id="functiongraph_01_1047__en-us_topic_0000001298667445_p3473121513359">Name of the function, which must meet the following requirements:</p>
|
|
<ul id="functiongraph_01_1047__en-us_topic_0000001298667445_ul54731315113516"><li id="functiongraph_01_1047__en-us_topic_0000001298667445_li16473161518354">Consists of 1 to 60 characters, and can contain letters, digits, hyphens (-), and underscores (_).</li><li id="functiongraph_01_1047__en-us_topic_0000001298667445_li24731715123517">Starts with a letter and ends with a letter or digit.</li></ul>
|
|
</td>
|
|
</tr>
|
|
<tr id="functiongraph_01_1047__en-us_topic_0000001298667445_row9474131511358"><td class="cellrowborder" valign="top" width="15.85%" headers="mcps1.3.3.2.3.4.2.3.1.1 "><p id="functiongraph_01_1047__en-us_topic_0000001298667445_p1047319152357">*Enterprise Project</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="84.15%" headers="mcps1.3.3.2.3.4.2.3.1.2 "><p id="functiongraph_01_1047__en-us_topic_0000001298667445_p647319159351">Select a created enterprise project and add the function to it. By default, <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b1707237131016">default</strong> is selected.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="functiongraph_01_1047__en-us_topic_0000001298667445_row34742015173516"><td class="cellrowborder" valign="top" width="15.85%" headers="mcps1.3.3.2.3.4.2.3.1.1 "><p id="functiongraph_01_1047__en-us_topic_0000001298667445_p11474315163517">Container Image</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="84.15%" headers="mcps1.3.3.2.3.4.2.3.1.2 "><p id="functiongraph_01_1047__en-us_topic_0000001298667445_p154223623012">Enter an image URL, that is, the location of the container image. You can click <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b3431182711474">View Image</strong> to view private and shared images. </p>
|
|
</td>
|
|
</tr>
|
|
<tr id="functiongraph_01_1047__en-us_topic_0000001298667445_row547451553516"><td class="cellrowborder" valign="top" width="15.85%" headers="mcps1.3.3.2.3.4.2.3.1.1 "><p id="functiongraph_01_1047__en-us_topic_0000001298667445_p15474101553510">Container Image Override</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="84.15%" headers="mcps1.3.3.2.3.4.2.3.1.2 "><ul id="functiongraph_01_1047__en-us_topic_0000001298667445_ul14741215183511"><li id="functiongraph_01_1047__en-us_topic_0000001298667445_li1474181533515"><strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b4700202851312">CMD</strong>: container startup command. Example: <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b18374162181320">/bin/sh</strong>. If no command is specified, the entrypoint or CMD in the image configuration will be used. Enter one or more commands separated with commas (,).</li><li id="functiongraph_01_1047__en-us_topic_0000001298667445_li94742156356"><strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b109381521411">Args</strong>: container startup parameter. Example: <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b205155463335">-args,value1</strong>. If no argument is specified, CMD in the image configuration will be used. Enter one or more arguments separated with commas (,).</li><li id="functiongraph_01_1047__en-us_topic_0000001298667445_li2474201520354"><strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b268890205511">Working Dir</strong>: working directory of the container. The folder path can only be <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b4668817459">/</strong> and cannot be created or modified. The path will be <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b119435513214">/</strong> by default if not specified.</li><li id="functiongraph_01_1047__en-us_topic_0000001298667445_li84745156353"><strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b3989039181512">User ID</strong>: user ID for running the image. If no user ID is specified, the default value <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b952735893319">1003</strong> will be used.</li><li id="functiongraph_01_1047__en-us_topic_0000001298667445_li5474141563511"><strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b20247105512155">Group ID</strong>: user group ID. If no user group ID is specified, the default value <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b399365918339">1003</strong> will be used.</li></ul>
|
|
</td>
|
|
</tr>
|
|
<tr id="functiongraph_01_1047__en-us_topic_0000001298667445_row747413155359"><td class="cellrowborder" valign="top" width="15.85%" headers="mcps1.3.3.2.3.4.2.3.1.1 "><p id="functiongraph_01_1047__en-us_topic_0000001298667445_p1347431553516">Agency</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="84.15%" headers="mcps1.3.3.2.3.4.2.3.1.2 "><p id="functiongraph_01_1047__en-us_topic_0000001298667445_p14741515103516">Select an agency with the <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b19542124631713">SWR Admin</strong> permission. To create an agency, see <a href="functiongraph_01_0920.html#functiongraph_01_0920__en-us_topic_0000001298507433_section17872123319473">Creating an Agency</a>.</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div class="note" id="functiongraph_01_1047__en-us_topic_0000001298667445_note8475015203512"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="functiongraph_01_1047__en-us_topic_0000001298667445_ul347541516357"><li id="functiongraph_01_1047__en-us_topic_0000001298667445_li9474201512352"><strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b7711730115810">Command</strong>, <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b14742183485812">Args</strong>, and <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b2032163920587">Working dir</strong> can contain up to 5120 characters.</li><li id="functiongraph_01_1047__en-us_topic_0000001298667445_li116601045102414">When a function is executed at the first time, the image is pulled from SWR, and the container is started during cold start of the function, which takes a certain period of time. If there is no image on a node during subsequent cold starts, an image will be pulled from SWR.</li><li id="functiongraph_01_1047__en-us_topic_0000001298667445_li156992027184912">Public and private images are supported. For details, see <a href="https://docs.otc.t-systems.com/software-repository-container/umn/image_management/setting_image_attributes.html" target="_blank" rel="noopener noreferrer">Setting Image Attributes</a>.</li><li id="functiongraph_01_1047__en-us_topic_0000001298667445_li13891636172512">The port of a custom container image must be 8000.</li><li id="functiongraph_01_1047__en-us_topic_0000001298667445_li1390615422610">The image package cannot exceed 10 GB. For a larger package, reduce the capacity. For example, mount the data of a question library to a container where the data was previously loaded through an external file system.</li><li id="functiongraph_01_1047__en-us_topic_0000001298667445_li133681917192613">FunctionGraph uses LTS to collect all logs that the container outputs to the console. These logs can be redirected to and printed on the console through standard output or an open-source log framework. The logs should include the system time, component name, code line, and key data, to facilitate fault locating.</li><li id="functiongraph_01_1047__en-us_topic_0000001298667445_li127784396113">When an out of memory (OOM) error occurs, view the memory usage in the function execution result.</li><li id="functiongraph_01_1047__en-us_topic_0000001298667445_li118281827115118">Functions must return a valid HTTP response.</li></ul>
|
|
</div></div>
|
|
</li><li id="functiongraph_01_1047__en-us_topic_0000001298667445_li896875313208"><strong id="functiongraph_01_1047__en-us_topic_0000001298667445_functiongraph_04_0101_b138464532075">Advanced Settings</strong>: <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_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_01_1047__en-us_topic_0000001298667445_functiongraph_04_0101_table586619443117" frame="border" border="1" rules="all"><caption><b>Table 2 </b>Parameters for configuring Collect Logs</caption><thead align="left"><tr id="functiongraph_01_1047__en-us_topic_0000001298667445_functiongraph_04_0101_row686618443112"><th align="left" class="cellrowborder" valign="top" width="32.31%" id="mcps1.3.3.2.4.3.2.3.1.1"><p id="functiongraph_01_1047__en-us_topic_0000001298667445_functiongraph_04_0101_p14866749313">Parameter</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="67.69%" id="mcps1.3.3.2.4.3.2.3.1.2"><p id="functiongraph_01_1047__en-us_topic_0000001298667445_functiongraph_04_0101_p178668423117">Description</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="functiongraph_01_1047__en-us_topic_0000001298667445_functiongraph_04_0101_row1886615419311"><td class="cellrowborder" valign="top" width="32.31%" headers="mcps1.3.3.2.4.3.2.3.1.1 "><p id="functiongraph_01_1047__en-us_topic_0000001298667445_functiongraph_04_0101_p11866144103115">Log Configuration</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="67.69%" headers="mcps1.3.3.2.4.3.2.3.1.2 "><p id="functiongraph_01_1047__en-us_topic_0000001298667445_functiongraph_04_0101_p1886610493115">You can select <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_functiongraph_04_0101_b1757312367911">Auto</strong> or <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_functiongraph_04_0101_b134872038395">Custom</strong>.</p>
|
|
<ul id="functiongraph_01_1047__en-us_topic_0000001298667445_functiongraph_04_0101_ul894114313424"><li id="functiongraph_01_1047__en-us_topic_0000001298667445_functiongraph_04_0101_li13941539425"><strong id="functiongraph_01_1047__en-us_topic_0000001298667445_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_01_1047__en-us_topic_0000001298667445_functiongraph_04_0101_li1713036164219"><strong id="functiongraph_01_1047__en-us_topic_0000001298667445_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_01_1047__en-us_topic_0000001298667445_functiongraph_04_0101_row1386618412312"><td class="cellrowborder" valign="top" width="32.31%" headers="mcps1.3.3.2.4.3.2.3.1.1 "><p id="functiongraph_01_1047__en-us_topic_0000001298667445_functiongraph_04_0101_p286619414315">Log Tag</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="67.69%" headers="mcps1.3.3.2.4.3.2.3.1.2 "><p id="functiongraph_01_1047__en-us_topic_0000001298667445_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_01_1047__en-us_topic_0000001298667445_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_01_1047__en-us_topic_0000001298667445_li1135748163814">(Optional) Deploy a new image.<div class="p" id="functiongraph_01_1047__en-us_topic_0000001298667445_p63272437525"><a name="functiongraph_01_1047__en-us_topic_0000001298667445_li1135748163814"></a><a name="en-us_topic_0000001298667445_li1135748163814"></a>On the <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b18457164219139">Code</strong> tab, click <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b1066683861312">Deploy Image</strong> on the right, enter the URL of the new image in the text box, and click <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b3591558181311">OK</strong>. To obtain the URL, perform the following operations:<ol type="a" id="functiongraph_01_1047__en-us_topic_0000001298667445_ol20691145735012"><li id="functiongraph_01_1047__en-us_topic_0000001298667445_li1718214315116">Log in to the SWR console. In the navigation pane, choose <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b101241539183613">My Images</strong>.</li><li id="functiongraph_01_1047__en-us_topic_0000001298667445_li3497122518527">Click the <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b128951313173">Private Images</strong> or <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b538612281175">Images From Others</strong> tab. In the image list, click the image name to go to the details page.</li><li id="functiongraph_01_1047__en-us_topic_0000001298667445_li15230164345620">Click the <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b15861212101914">Tags</strong> tab, copy the download command in the image tag list, and delete <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b4584548161916">docker pull</strong> from the command to obtain the image URL.</li></ol>
|
|
</div>
|
|
</li></ol>
|
|
</div>
|
|
<div class="section" id="functiongraph_01_1047__en-us_topic_0000001298667445_section10470141217569"><h4 class="sectiontitle">Sample Code</h4><p id="functiongraph_01_1047__en-us_topic_0000001298667445_p197632055122512">The following uses <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b107251133124110">Node.js Express</strong> as an example. During function initialization, FunctionGraph uses the POST method to access the <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b77261933134110">/init</strong> path (optional). Each time when a function is called, FunctionGraph uses the POST method to access the <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b472643311417">/invoke</strong> path. The function obtains <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b123813174427">context</strong> from <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b162382170425">req.headers</strong>, obtains <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b1023911171422">event</strong> from <strong id="functiongraph_01_1047__en-us_topic_0000001298667445_b424041720422">req.body</strong>, and returns an HTTP response struct.</p>
|
|
<pre class="screen" id="functiongraph_01_1047__en-us_topic_0000001298667445_screen14751413265">const express = require('express');
|
|
const app = express();
|
|
const PORT = 8000;
|
|
|
|
app.post('/init', (req, res) => {
|
|
res.send('Hello init\n');
|
|
});
|
|
|
|
app.post('/invoke', (req, res) => {
|
|
res.send('Hello invoke\n');
|
|
});
|
|
|
|
app.listen(PORT, () => {
|
|
console.log(`Listening on http://localhost:${PORT}`);
|
|
});</pre>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="functiongraph_01_0150_0.html">Creating a Function</a></div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<script language="JavaScript">
|
|
<!--
|
|
image_size('.imgResize');
|
|
var msg_imageMax = "view original image";
|
|
var msg_imageClose = "close";
|
|
//--></script> |