All Products
Document Center

Create a function

Last Updated: May 30, 2019

A function is an object that the system uses for scheduling and execution. Functions must be associated with services. All functions of a service share the properties of the service, such as service authorizations and logging configurations.

Function properties

When you create a function, specify the following properties:

  • (Required) functionName: Indicates the function name. This name must be unique under the current service and meet the following requirements:
    • The name can consist of letters, numbers, underscores (_), and hyphens (-).
    • The name must start with a letter or an underscore (_).
    • The name is case-sensitive.
    • The name must be between 1 to 128 characters in length.
  • (Required) runtime: Indicates the runtime type of the function.
  • (Required) code: Indicates the code package. It should be jar package in java runtime, and should be zip package in other runtime. These packages can be stored in OSS or directly uploaded.
  • (Required) handler: Indicates the processing function. This property is used by Function Compute for calling certain functions.
  • (Optional) description: Displays the details of the specified function. This property is not required in Function Compute. However, we recommend that you add a concise description to more easily identify the function.
  • (Optional) timeout: Indicates the maximum execution time of the function, in seconds.
  • (Optional) MemorySize: Indicates the memory required for function execution, in MB. The value of this property is in the range of 128 to 3072 and increases at increments of 64.

All properties except for the function name can be modified.

Function runtime types

Runtime type Description Reference
nodejs6 Node.js 6.10.3 Node.js runtime environments
nodejs8 Node.js 8.9.0 Node.js runtime environments
python2.7 Python 2.7 Python runtime environments
python3 Python 3.6 Python runtime environments
java8 Java 8 Java runtime environments
php7.2 Php 7.2.7 Php Runtime

Create or update function by using fcli

When you run fcli in shell mode, you can enter the mkf/upf command to create or update a function, and type the info command to view function properties. For example, to create and update the world function in the hello service, follow these steps:

  1. Create a service named mks hello.

  2. Create a basic function file index.js locally and save it to the code folder.

    1. 'use strict';
    2. console.log('loading function');
    3. module.exports.handler = function(event, context, callback) {
    4. console.log('Receive event:', event.toString());
    5. callback(null, event);
    6. };
  3. Create a world function.

    1. mkf hello/world -t nodejs6 -h index.handler -d code
  4. Run the upf hello/world --description "this is world function" command to update the details of the world function.

  5. Run the info hello/world command to check the properties of the world function.


Basic operations.