This document describes how to develop a simple
Hello World web service in the Serverless Cloud Function (SCF) Console.
- You have already registered a Tencent Cloud account. If you haven't, Click Here to sign up.
- You have already logged in to the SCF Console.
- Click Functions on the left sidebar to enter the "Functions" page.
- Select Guangzhou at the top of the page and click Create, as shown below:
- Enter the basic information of the function on the "Create Function" page and click Next, as shown below:
- Function Name: "hello-world".
- Runtime Environment: Select "Python 2.7".
- Creation Method: Select "Template Function".
- Template Search: After entering "helloworld", press "Enter" to search for and select the "helloworld" template.
- Keep the default function configuration and click Finish, as shown below:
After the function is created, you will be automatically redirected to the "Function Configuration" page where you can view the configuration information.
- The parameter of "Execution Method" is set to "index.main_handler", indicating that the SCF console will automatically save this code as an
index.py file, compress and upload it to SCF for function creation.
- The entry function in the sample code is
main_handler, which has the following main parameters:
event parameter: Gets information of the triggering source.
context parameter: Gets the environment and configuration information of this function.
- Select Function Code to view or edit the function code online.
Deploying a function (with trigger configured)
- After editing the function code online, click Save and the function will be deployed.
- On the details page of the created function, select Triggers and click Add a Trigger, as shown below:
- On the Add a Trigger page, set "Trigger Type" to "API Gateway Trigger" and keep other default parameters, as shown below:
- Click Save to complete the function deployment and trigger configuration.
Testing function deployment
Select Function Code and click Test to run the code and return the test result, as shown below:
- If you need to replace the test template or its content, edit the function content directly or select Current Test Template, replace it, and then click Save.
- Different test templates simulate different trigger message sources, and the messages passed between different triggers and SCF have predetermined data structures. For more information, see Trigger Overview
During this test, SCF will get the data structure of the "Hello world event template" in the
event parameter of
"key1": "test value 1",
"key2": "test value 2"
Testing Trigger configuration
- After a trigger is successfully created, an access path will be generated on the "Triggers" page of the function, as shown below:
- If "hello from scf" is displayed when you open the access path in a browser, the function is successfully deployed.
On the details page of a created function, select Execution Logs to view the detailed logs of the function, as shown below:
For more information on logs, see Function Logs.
Viewing monitoring information
On the details page of a created function, select Monitoring Information to view metrics such as the number of function invocations and execution runtime, as shown below:
The minimal granularity of monitoring statistics is 1 minute. You need to wait for 1 minute before you can view the current monitoring record.
For more information on monitoring, see Descriptions of monitoring metrics.
Configuring an alarm
On the details page of a created function, click Create Alarm to configure an alarm policy for the function to monitor its health status, as shown below:
For more information on how to configure an alarm, see Alarm configuration description.