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.
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")
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 main.py file.
initializerfunction has only one input parameter: the
contextparameter. This parameter is defined the same as the
contextparameter in event functions.
- In the
initialization_timeoutfields 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.