Function Compute allows you to connect to running function instances and run command-line interface (CLI) commands directly in the runtime environment. You can use this feature through the Function Compute console or the Function Compute SDK.
How it works
Use this feature to debug issues, profile performance, or inspect the execution environment of your functions in real time.
In Function Compute, each request is handled by an instance, which serves as the execution environment. Function Compute allocates the most appropriate instance for each request and releases the instance after the request is processed.
CLI-based instance management lets you open an interactive shell session on a running instance, giving you direct access to the actual runtime environment. For example, you can:
Inspect environment details such as file system layout and environment variables.
Run diagnostic tools such as profiling or core dump to identify performance bottlenecks.
Check running processes and resource usage.
Prerequisites
Before you begin, make sure the following requirements are met:
A function is created. For more information, see the "Create a function" section of the Manage functions topic.
Simple Log Service is activated. For more information, see Step 1: Activate Simple Log Service.
If you use a Custom Container runtime, your container image must include /bin/bash or /bin/sh. Otherwise, the instance terminal cannot be launched.
Usage notes
| Item | Details |
|---|---|
| Supported instances | You can only run commands on live instances, which include long-running provisioned instances and active on-demand instances. If an on-demand instance has been idle for a specified period, it is released and can no longer be accessed. |
| Concurrency | CLI-based instance management requests do not consume the concurrency quota of an instance. You can invoke a function and manage an instance of that function by using CLI at the same time, even if the Single Instance Concurrency parameter of the function is set to 1. |
| Billing | Each CLI session on an instance is counted as a function invocation. If you establish a WebSocket connection to an instance, the instance stays active until the connection is terminated. You are charged based on the same metering rules as regular function invocations. |
| Console idle timeout | If no data transfer occurs on the logon interface of the instance in the console, the instance is disconnected after 10 minutes of idle time. |
Running commands on an instance that is processing an online request may alter the runtime environment and cause the request to fail. The execution of subsequent tasks on the instance may also be affected. Failures caused by running CLI commands on instances are not covered by the Service-Level Agreement (SLA) of Function Compute.
Connect to an instance in the console
Log on to the Function Compute console. In the left-side navigation pane, click Services & Functions.
In the top navigation bar, select a region. On the Services page, click the desired service.
In the top navigation bar, select a region. On the Services page, click the desired service.
On the Functions page, click the desired function.
On the function details page, click the Instances tab. Find the instance that you want to connect to, and click Connect in the Actions column.
In the Note message, read the content and click I understand the risks.
You are redirected to the CLI page of the instance, where you can run commands based on your business requirements.
You can only run commands on instances that are in the Running state. You cannot connect to an instance that has been released.
Use the SDK
You can call the Function Compute SDK to run commands on instances programmatically. For more information about the SDKs supported by Function Compute, see SDKs.