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>
119 lines
14 KiB
HTML
119 lines
14 KiB
HTML
<a name="functiongraph_01_0209"></a><a name="functiongraph_01_0209"></a>
|
|
|
|
<h1 class="topictitle1">Using a CTS Trigger</h1>
|
|
<div id="body32001227"><p id="functiongraph_01_0209__en-us_topic_0000001298667437_p4849928173413">For details about the CTS event source, see section "Supported Event Sources".</p>
|
|
<div class="section" id="functiongraph_01_0209__en-us_topic_0000001298667437_section97094317346"><h4 class="sectiontitle">Prerequisites</h4><p id="functiongraph_01_0209__en-us_topic_0000001298667437_p1035211375719">You have created an agency on IAM. For details, see <a href="functiongraph_01_0920.html#functiongraph_01_0920">Configuring Agency Permissions</a>.</p>
|
|
</div>
|
|
<div class="section" id="functiongraph_01_0209__en-us_topic_0000001298667437_section1079628104617"><h4 class="sectiontitle">Creating a CTS Trigger</h4><ol id="functiongraph_01_0209__en-us_topic_0000001298667437_ol6901314154718"><li id="functiongraph_01_0209__en-us_topic_0000001298667437_li155710337386"><span>Log in to the FunctionGraph console. In the navigation pane, choose <strong id="functiongraph_01_0209__en-us_topic_0000001298667437_b18967152316914">Functions</strong> > <strong id="functiongraph_01_0209__en-us_topic_0000001298667437_b11967142315919">Function List</strong>.</span></li><li id="functiongraph_01_0209__en-us_topic_0000001298667437_li1140195018364"><span>On the <strong id="functiongraph_01_0209__en-us_topic_0000001298667437_b14269351401">Function List</strong> page, click <strong id="functiongraph_01_0209__en-us_topic_0000001298667437_b92705534019">Create Function</strong> in the upper right corner.</span></li><li id="functiongraph_01_0209__en-us_topic_0000001298667437_li477419293572"><span>Set the following parameters:</span><p><ul id="functiongraph_01_0209__en-us_topic_0000001298667437_ul16865122833514"><li id="functiongraph_01_0209__en-us_topic_0000001298667437_li14680330124215"><strong id="functiongraph_01_0209__en-us_topic_0000001298667437_b6168012353">Function Name</strong>: Enter a function name, for example, <strong id="functiongraph_01_0209__en-us_topic_0000001298667437_b21684163517">HelloWorld</strong>.</li><li id="functiongraph_01_0209__en-us_topic_0000001298667437_li1737435210422"><strong id="functiongraph_01_0209__en-us_topic_0000001298667437_b52371989353">Agency</strong>: Select <strong id="functiongraph_01_0209__en-us_topic_0000001298667437_b423712813357">Use no agency</strong>.</li><li id="functiongraph_01_0209__en-us_topic_0000001298667437_li134611116112"><strong id="functiongraph_01_0209__en-us_topic_0000001298667437_b132546132268">Enterprise Project</strong>: Select <strong id="functiongraph_01_0209__en-us_topic_0000001298667437_b4254101392611">default</strong>.</li><li id="functiongraph_01_0209__en-us_topic_0000001298667437_li118751474316"><strong id="functiongraph_01_0209__en-us_topic_0000001298667437_b132831119351">Runtime</strong>: Select <strong id="functiongraph_01_0209__en-us_topic_0000001298667437_b102911119354">Python 2.7</strong>.</li></ul>
|
|
</p></li><li id="functiongraph_01_0209__en-us_topic_0000001298667437_li1553823418368"><span>Click <strong id="functiongraph_01_0209__en-us_topic_0000001298667437_b16819111552812">Create Function</strong>.</span></li><li id="functiongraph_01_0209__en-us_topic_0000001298667437_li763684273619"><span>On the <strong id="functiongraph_01_0209__en-us_topic_0000001298667437_b1885421419404">Code</strong> tab page, copy the following code to the code window and click <strong id="functiongraph_01_0209__en-us_topic_0000001298667437_b1985541411407">Deploy</strong>.</span><p><pre class="screen" id="functiongraph_01_0209__en-us_topic_0000001298667437_screen4706114217365"># -*- coding:utf-8 -*-
|
|
'''
|
|
CTS trigger event:
|
|
{
|
|
"cts": {
|
|
"time": "",
|
|
"user": {
|
|
"name": "userName",
|
|
"id": "",
|
|
"domain": {
|
|
"name": "domainName",
|
|
"id": ""
|
|
}
|
|
},
|
|
"request": {},
|
|
"response": {},
|
|
"code": 204,
|
|
"service_type": "FunctionGraph",
|
|
"resource_type": "",
|
|
"resource_name": "",
|
|
"resource_id": {},
|
|
"trace_name": "",
|
|
"trace_type": "ConsoleAction",
|
|
"record_time": "",
|
|
"trace_id": "",
|
|
"trace_status": "normal"
|
|
}
|
|
}
|
|
'''
|
|
def handler (event, context):
|
|
trace_name = event["cts"]["resource_name"]
|
|
timeinfo = event["cts"]["time"]
|
|
print(timeinfo+' '+trace_name)</pre>
|
|
</p></li><li id="functiongraph_01_0209__en-us_topic_0000001298667437_li48821313121717"><span>Choose <strong id="functiongraph_01_0209__en-us_topic_0000001298667437_en-us_topic_0000001251588440_b289510228329">Configuration</strong> > <strong id="functiongraph_01_0209__en-us_topic_0000001298667437_en-us_topic_0000001251588440_b156971032183216">Triggers</strong> and click <strong id="functiongraph_01_0209__en-us_topic_0000001298667437_en-us_topic_0000001251588440_b98432283337">Create Trigger</strong>.</span><p><div class="fignone" id="functiongraph_01_0209__en-us_topic_0000001298667437_en-us_topic_0000001251588440_fig546212168431"><span class="figcap"><b>Figure 1 </b>Creating a trigger</span><br><span><img id="functiongraph_01_0209__en-us_topic_0000001298667437_en-us_topic_0000001251588440_image94621716114320" src="en-us_image_0000001679340817.png"></span></div>
|
|
</p></li><li id="functiongraph_01_0209__en-us_topic_0000001298667437_li3834144445"><span>Configure the trigger information.</span><p>
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="functiongraph_01_0209__en-us_topic_0000001298667437_table1682181464418" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Trigger information</caption><thead align="left"><tr id="functiongraph_01_0209__en-us_topic_0000001298667437_row181914164413"><th align="left" class="cellrowborder" valign="top" width="22.34%" id="mcps1.4.3.2.7.2.1.2.3.1.1"><p id="functiongraph_01_0209__en-us_topic_0000001298667437_p1381101413445">Parameter</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="77.66%" id="mcps1.4.3.2.7.2.1.2.3.1.2"><p id="functiongraph_01_0209__en-us_topic_0000001298667437_p9818143441">Description</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="functiongraph_01_0209__en-us_topic_0000001298667437_row1572625334418"><td class="cellrowborder" valign="top" width="22.34%" headers="mcps1.4.3.2.7.2.1.2.3.1.1 "><p id="functiongraph_01_0209__en-us_topic_0000001298667437_p272712538443">Trigger Type</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="77.66%" headers="mcps1.4.3.2.7.2.1.2.3.1.2 "><p id="functiongraph_01_0209__en-us_topic_0000001298667437_p1372735315444">Select <strong id="functiongraph_01_0209__en-us_topic_0000001298667437_b67691284372">Cloud Trace Service (CTS)</strong>.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="functiongraph_01_0209__en-us_topic_0000001298667437_row14815149447"><td class="cellrowborder" valign="top" width="22.34%" headers="mcps1.4.3.2.7.2.1.2.3.1.1 "><p id="functiongraph_01_0209__en-us_topic_0000001298667437_p3811214184410">Event Notification Name</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="77.66%" headers="mcps1.4.3.2.7.2.1.2.3.1.2 "><p id="functiongraph_01_0209__en-us_topic_0000001298667437_p13811414134419">Enter a notification name, for example, <strong id="functiongraph_01_0209__en-us_topic_0000001298667437_b1879419504377">Test</strong>.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="functiongraph_01_0209__en-us_topic_0000001298667437_row1827147443"><td class="cellrowborder" valign="top" width="22.34%" headers="mcps1.4.3.2.7.2.1.2.3.1.1 "><p id="functiongraph_01_0209__en-us_topic_0000001298667437_p3821214174412">Service Type</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="77.66%" headers="mcps1.4.3.2.7.2.1.2.3.1.2 "><p id="functiongraph_01_0209__en-us_topic_0000001298667437_p1382181411440">Select <strong id="functiongraph_01_0209__en-us_topic_0000001298667437_b114441275384">FunctionGraph</strong>.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="functiongraph_01_0209__en-us_topic_0000001298667437_row482131434413"><td class="cellrowborder" valign="top" width="22.34%" headers="mcps1.4.3.2.7.2.1.2.3.1.1 "><p id="functiongraph_01_0209__en-us_topic_0000001298667437_p28241412445">Resource Type</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="77.66%" headers="mcps1.4.3.2.7.2.1.2.3.1.2 "><p id="functiongraph_01_0209__en-us_topic_0000001298667437_p138210145444">Resource types supported by the selected service, such as triggers, instances, and functions.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="functiongraph_01_0209__en-us_topic_0000001298667437_row1382151411448"><td class="cellrowborder" valign="top" width="22.34%" headers="mcps1.4.3.2.7.2.1.2.3.1.1 "><p id="functiongraph_01_0209__en-us_topic_0000001298667437_p158261454420">Trace Name</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="77.66%" headers="mcps1.4.3.2.7.2.1.2.3.1.2 "><p id="functiongraph_01_0209__en-us_topic_0000001298667437_p18271416446">Operations that can be performed on the selected resource type, such as creating or deleting a trigger.</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</p></li><li id="functiongraph_01_0209__en-us_topic_0000001298667437_li1826224523413"><span>Click <strong id="functiongraph_01_0209__en-us_topic_0000001298667437_b9263320392">OK</strong>.</span></li></ol>
|
|
</div>
|
|
<div class="section" id="functiongraph_01_0209__en-us_topic_0000001298667437_section1581734219447"><h4 class="sectiontitle">Configuring a CTS Event to Trigger the Function</h4><ol id="functiongraph_01_0209__en-us_topic_0000001298667437_ol1220710475819"><li id="functiongraph_01_0209__en-us_topic_0000001298667437_li3847165811510"><span>Return to the FunctionGraph console. In the navigation pane, choose <strong id="functiongraph_01_0209__en-us_topic_0000001298667437_b75638116291526">Functions</strong> > <strong id="functiongraph_01_0209__en-us_topic_0000001298667437_b141817874991526">Function List</strong>.</span></li><li id="functiongraph_01_0209__en-us_topic_0000001298667437_li1080841135117"><span>Click the function to be configured to go to the function details page.</span></li><li id="functiongraph_01_0209__en-us_topic_0000001298667437_li13470153605820"><span>On the function details page, select a version, and click <strong id="functiongraph_01_0209__en-us_topic_0000001298667437_b1229350124017">Test</strong>. The <strong id="functiongraph_01_0209__en-us_topic_0000001298667437_b42991805407">Configure Test Event</strong> dialog box is displayed.</span></li><li id="functiongraph_01_0209__en-us_topic_0000001298667437_li107612036409"><span>Set the parameters described in <a href="#functiongraph_01_0209__en-us_topic_0000001298667437_table19101881852">Table 2</a> and click <strong id="functiongraph_01_0209__en-us_topic_0000001298667437_b66791742111619">Save</strong>.</span><p>
|
|
<div class="tablenoborder"><a name="functiongraph_01_0209__en-us_topic_0000001298667437_table19101881852"></a><a name="en-us_topic_0000001298667437_table19101881852"></a><table cellpadding="4" cellspacing="0" summary="" id="functiongraph_01_0209__en-us_topic_0000001298667437_table19101881852" frame="border" border="1" rules="all"><caption><b>Table 2 </b>Test event information</caption><thead align="left"><tr id="functiongraph_01_0209__en-us_topic_0000001298667437_row18991818517"><th align="left" class="cellrowborder" valign="top" width="28.000000000000004%" id="mcps1.4.4.2.4.2.1.2.3.1.1"><p id="functiongraph_01_0209__en-us_topic_0000001298667437_p1199882517">Parameter</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="72%" id="mcps1.4.4.2.4.2.1.2.3.1.2"><p id="functiongraph_01_0209__en-us_topic_0000001298667437_p1399481516">Description</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="functiongraph_01_0209__en-us_topic_0000001298667437_row15991688510"><td class="cellrowborder" valign="top" width="28.000000000000004%" headers="mcps1.4.4.2.4.2.1.2.3.1.1 "><p id="functiongraph_01_0209__en-us_topic_0000001298667437_p99910817514">Configure Test Event</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="72%" headers="mcps1.4.4.2.4.2.1.2.3.1.2 "><p id="functiongraph_01_0209__en-us_topic_0000001298667437_p699481551">You can choose to create a test event or edit an existing one.</p>
|
|
<p id="functiongraph_01_0209__en-us_topic_0000001298667437_p189928655">Use the default option <strong id="functiongraph_01_0209__en-us_topic_0000001298667437_b104194975910">Create new test event</strong>.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="functiongraph_01_0209__en-us_topic_0000001298667437_row17100881156"><td class="cellrowborder" valign="top" width="28.000000000000004%" headers="mcps1.4.4.2.4.2.1.2.3.1.1 "><p id="functiongraph_01_0209__en-us_topic_0000001298667437_p19988857">Event Template</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="72%" headers="mcps1.4.4.2.4.2.1.2.3.1.2 "><p id="functiongraph_01_0209__en-us_topic_0000001298667437_p3991681155">Select <strong id="functiongraph_01_0209__en-us_topic_0000001298667437_b662635311598">cts-event-template</strong>.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="functiongraph_01_0209__en-us_topic_0000001298667437_row15100481555"><td class="cellrowborder" valign="top" width="28.000000000000004%" headers="mcps1.4.4.2.4.2.1.2.3.1.1 "><p id="functiongraph_01_0209__en-us_topic_0000001298667437_p410058956">Event Name</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="72%" headers="mcps1.4.4.2.4.2.1.2.3.1.2 "><p id="functiongraph_01_0209__en-us_topic_0000001298667437_p010028051">Enter an event name, for example, <strong id="functiongraph_01_0209__en-us_topic_0000001298667437_b59690247403">cts-test</strong>.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="functiongraph_01_0209__en-us_topic_0000001298667437_row111012081952"><td class="cellrowborder" valign="top" width="28.000000000000004%" headers="mcps1.4.4.2.4.2.1.2.3.1.1 "><p id="functiongraph_01_0209__en-us_topic_0000001298667437_p14100208953">Event data</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="72%" headers="mcps1.4.4.2.4.2.1.2.3.1.2 "><p id="functiongraph_01_0209__en-us_topic_0000001298667437_p14100881055">The system automatically loads the event data in the CTS event template. You can modify the event data as required.</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</p></li><li id="functiongraph_01_0209__en-us_topic_0000001298667437_li141018814514"><span>Click <strong id="functiongraph_01_0209__en-us_topic_0000001298667437_b638322221415">Test</strong>. The function test result is displayed.</span></li></ol>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="functiongraph_01_0200.html">Creating Triggers</a></div>
|
|
</div>
|
|
</div>
|
|
|