An initializer function is used to ensure specific business logic is successfully executed on the same instance only once. This topic describes the structure and features of Python initializer functions.

Background information

Function Compute supports the following Python runtime environments:

  • Python 2.7 ( runtime = python2.7 )
  • Python 3.6 ( runtime = python3 )


The following code defines a simple initializer function. For more information, see Initializer function.

def my_initializer(context):    
    print("hello world")

Function name

The my_initializer parameter must correspond to the initializer field that you specify when you add the initializer feature. For example, if you set initializer to main.my_initializer when you create a function, after the initializer feature is configured, Function Compute loads the my_initializer function defined in the file.


  • An initializer function has only one input parameter: the context parameter. This parameter is defined the same as the context parameter in event functions.
  • In the context parameter, the initializer and initialization_timeout fields are specifically designed for initializer functions. If these two fields are not specified, the initializer function will not be executed.
  • Initializer functions do not return any value. Return logic appended to initializer functions does not take effect.