You can connect to an instance from the Function Compute console or by using Function Compute SDKs and perform CLI-based operations on the instance. This topic describes how to connect to an instance in the Function Compute console and run commands on the instance.
Background
Instances are execution environments of requests. Function Compute allocates the most appropriate instance for each request and releases the instance after the request is executed. CLI-based instance management allows you to run commands on instances in real execution 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 active instances, which include long-running provisioned instances and active on-demand instances. If an on-demand instance is released or in an unhealthy state and is about to be destroyed, you may not be able to log on to the instance to perform operations.
CLI-based management requests do not occupy the concurrency quota of an instance. Even if the instance concurrency of a function is set to 1, you can invoke the function and perform CLI-based operations on instances of the function at the same time.
Each command that you run on an instance is considered as a function invocation. If you establish a WebSocket connection to an instance for CLI-based management, the instance stays active until you terminate the connection. You are charged based on the metering rules for regular function invocations. If you connect to an instance from the Function Compute console for CLI-based management, the instance is automatically disconnected 10 minutes after the last piece of data is transferred from the Function Compute console.
If you use a custom image in a Custom Container runtime, make sure that the container contains the
/bin/bash
or/bin/sh
directory. Otherwise, the instance client cannot be started.
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 also affected. If requests fail due to CLI-based instance management, the failures are not counted in the service-level agreement (SLA) of Function Compute.
Before you start
Procedure
Log on to the Function Compute console. In the left-side navigation pane, click Functions.
In the top navigation bar, select a region. On the Functions page, click the function that you want to manage.
On the function details page, click the Instances tab.
In the instance list, find the instance that you want to manage and click Connect in the Actions column.
In the message that appears, read the message. Then, click I understand the risks.
You are redirected to the CLI page of the instance. You can run commands based on your business requirements.
You can connect to and perform CLI-based operations only on instances in the Running state. If an instance is destroyed, you cannot connect to the instance.