How do I stop an instance?

Updated at:
Copy as MD

Function Compute has no direct interface to stop an instance. Use one of the following indirect methods based on your scenario: set a timeout, cancel client requests, stop asynchronous invocations, or delete the function.

Note

If an instance stays active 3–5 minutes after a request finishes, check whether provisioned instances are enabled. If they are, remove them to free the instance. For more information, see Configure provisioned instances.

Choose a method

ScenarioRecommended method
Function is running longer than expectedSet a timeout period
Function is synchronously invoked and you want to stop it nowCancel client requests
Function has an asynchronous invocation in progressStop the asynchronous invocation
You no longer need the functionDelete the function

Stop an instance

Set a timeout period

Set a timeout period on the function to bound execution time. When the timeout elapses, the function exits automatically and returns an error.

Consider two goals when setting the timeout:

  • Allow enough time for the function to complete under normal conditions.

  • Set a reasonable upper limit to prevent runaway executions.

For configuration steps, see Manage functions.

Cancel client requests

For synchronous invocations, cancel the request on the client side. The instance no longer processes requests after cancellation. After all in-flight requests finish and no new requests arrive for a set period, the instance is automatically reclaimed.

Stop asynchronous invocations

If the asynchronous task feature is enabled, stop a running invocation from the Function Compute console or by calling the StopStatefulAsyncInvocation API operation. After the invocation stops and no new requests arrive for a set period, the instance is automatically reclaimed.

Delete the function

Delete the function to reclaim all its instances. Any requests already allocated to those instances fail.

What's next