All Products
Search
Document Center

Function Compute (2.0):Run commands to manage function instances

Last Updated:Feb 26, 2024

You can use the Function Compute console or the Function Compute SDK to log on to instances and run command line interface (CLI) commands on the instances. This topic describes how to connect to an instance in the Function Compute console and run commands on the instance.

Background

In Function Compute, an instance is an execution environment for requests. Before you use an instance to execute requests, Function Compute allocates the most suitable instance to each request. After the request is executed, Function Compute releases the instance. CLI-based instance management allows you to run commands on instances in actual runtime environments. For example, you can connect to an instance and check the environment details or collect context information by using tools such as Profiling or Coredump to optimize performance.

Usage notes

  • You can run commands only on live instances, which include long-running provisioned instances and active on-demand instances. If an on-demand instance is idle for a specified period of time, the instance times out and is released. After the instance is released, you can no longer run commands on the instance.

  • CLI-based instance management requests do not consume the concurrency quota of an instance. You can invoke a function and manage an instance of the function by using CLI at the same time, even if the Single Instance Concurrency parameter of the function is set to 1.

  • Each time you run commands on an instance is considered a function invocation. If you establish a WebSocket connection to an instance by using CLI, the instance stays active until the connection is terminated. You are charged based on the same metering rules for function invocations. If no data transfer occurs on the logon interface of the instance in the console, the instance is disconnected after 10 minutes of idle period.

  • If you use a Custom Container runtime, make sure that the container that you use includes the /bin/bash or /bin/sh directory. Otherwise, you cannot launch an instance terminal.

Note

If you run commands on an instance that is executing an online request, the online environment may be changed, and the online request may fail due to the change. The execution of subsequent tasks on the instance is affected. If requests fail because you run CLI commands, the failures are not counted in the service-level agreement (SLA) of Function Compute.

Prerequisites

Procedure

  1. Log on to the Function Compute console. In the left-side navigation pane, click Services & Functions.

  2. In the top navigation bar, select a region. On the Services page, click the desired service.

  3. On the Functions page, click the desired function.

  4. On the function details page, click the Instances tab, find the instance to which you want to log on, and click Connect to Instance in the Actions column.

  5. In the Note message, read the message and click I understand the risks.

    You are redirected to the CLI page of the instance. You can run commands based on your business requirements.

Note

You can run commands only on instances that are in the Running state. You cannot log on to an instance that is released.

More information

You can call the Function Compute SDK to run commands on instances. For more information about the SDKs supported by Function Compute, see SDKs.