With Function Compute, you do not need to purchase and manage infrastructure such as servers. You need to only write and upload code or images to create elastic and reliable applications. This topic describes how to quickly create a function in the Function Compute console. In this topic, a simple serverless Hello World function is used as an example.
Prerequisites
You have registered an Alibaba Cloud account and completed real-name verification.
Procedure
Step 1: Activate Function Compute
Go to the Function Compute homepage.
Click Console. The page for trial plans for new users is displayed. Then, click Buy Now to activate Function Compute and go to the Function Compute console.
NoteIf your Alibaba Cloud account is registered on or after August 27, 2024 and has completed the real-name verification, Function Compute is automatically activated for you. You can obtain a free trial plan this first time you log on to the Function Compute console. For more information, see Trial quotas.
We recommend that you use an Alibaba Cloud account to activate Function Compute and use Function Compute as a Resource Access Management (RAM) user.
If you have already activated Function Compute, you are redirected to the Function Compute console.
(Optional). If this is the first time you log on to the Function Compute console, the Alibaba Cloud Service Authorization message appears. Click OK.
After the authorization, Function Compute can access other Alibaba Cloud resources, such as Virtual Private Cloud (VPC), Elastic Compute Service (ECS), Simple Log Service, and Container Registry resources. For more information about service-linked roles, see Service-linked role of Function Compute.
Step 2: Create an event function
Log on to the Function Compute console, select a region, and click Create Function.
On the page that appears, select Event Function, configure Function Name, and then click Create. In this example, Sample Code is selected. For more information about the parameters, see Create an event function.
Step 3: Verify the result
On the Function Details page, click the Code tab and click Test Function.
After the execution, hello world is returned.
More information
For detailed information of function creation and parameters, see Create a function.
For more information about the programming languages of functions, see Code development.
Function Compute allows you to use Serverless Devs to build, debug, and deploy applications. For more information, see Use Serverless Devs to manage functions.
Functions in Function Compute can be directly triggered or triggered by using events. For more information about event-triggered functions, see Trigger overview.
If the "Unable to import module 'index'" error occurs when your function is being executed, check whether the handler is correctly configured and whether the required dependencies are installed. For more information, see Install a third-party dependency for a function.