How do I stop an instance?
Function Compute does not provide an interface to directly stop an instance. You can stop a running instance by using indirect methods, such as canceling client requests, configuring a timeout period, or deleting the function.
If an instance is not released 3 to 5 minutes after a request ends, we recommend that you first check whether the function is configured with provisioned instances. If it is, you can delete the provisioned instances to release the instance.
Ways to stop an instance
-
Set a timeout period
You can set a timeout period for a function. When the timeout period elapses, the function automatically exits and reports an error. For more information, see Manage functions.
-
Cancel client requests
If your function is invoked synchronously, the function stops running as soon as the client cancels the request. After the request ends, if no new requests arrive for a period of time, the instance is automatically reclaimed.
-
Stop an asynchronous task in the console or by using an API operation
If the asynchronous task mode is enabled for your function, you can stop the running task in the Function Compute console or by calling the StopStatefulAsyncInvocation API operation. After the task stops, if no new requests arrive for a period of time, the instance is automatically reclaimed.
-
Delete the function
You can also delete the function to forcibly reclaim the instances. Any requests that the instances are processing fail.
Related documentation
-
For information about the two instance modes of Function Compute, see Instance modes.
-
For information about how to delete a function or modify its configurations, see Manage functions.