When you debug a function in an on-premises environment, you can run the s proxied
command to implement interconnection between on-premises and cloud applications.
This helps you improve development efficiency. This topic describes the basic principles
of interconnection between on-premises and cloud applications. This topic also describes
how to implement interconnection between on-premises and cloud applications to access
ApsaraDB RDS for MySQL and Apsara File Storage NAS, and implement breakpoint debugging
during interconnection between on-premises and cloud applications.
Basic principles
In the Serverless field, debugging has always been a pain point for developers. Although some cloud service providers provide some tools to resolve this problem, interconnection between the on-premises execution environment and the cloud environment cannot be implemented because these tools focus on simulating the on-premises execution environment and parameter stage. Therefore, to implement interconnection between the on-premises execution environment and the cloud environment, Serverless Devs allows you to configure interconnection between on-premises and cloud applications.

ServiceConfig
parameter in the s.yaml file to create a helper function, as shown in the preceding figure. This way, the
service configurations and network environment of the helper function (C) are the
same as those of a function to be debugged. The following requirements can be met
after the tunnel for interconnection between on-premises and cloud applications is
created:
- The container in which functions are executed in the on-premises environment can access
Alibaba Cloud services. For example, the container can use the following types of
endpoints to access Alibaba Cloud services:
- VPC endpoint, such as the VPC endpoint of NAS, ApsaraDB RDS, or Message Queue for Apache Kafka
- Internal endpoint, such as the internal endpoint of OSS
- Execution inbound traffic, such as context and event parameter information, is real traffic from the cloud.
You can use triggers or use SDKs to run the s proxied command to invoke helper functions (C). The request traffic is returned to the on-premises debugging instance (A), which is the container in which functions are executed in the on-premises environment. In this case, the execution inbound traffic is real traffic from the cloud.
- The code must be mounted to the container in which functions are executed in the on-premises environment (A).
- You can use the
--debug-port
parameter to specify the port mapping between the integrated development environment (IDE) and the container in which functions are executed in the on-premises environment.
Sample code
Sample code | Sample s.yaml file content |
---|---|
|
|
Prerequisites
- Install Serverless Devs and Docker.
- Configure Serverless Devs
- Optional:Attach the following policy to a RAM user to grant permissions on Tunnel Service:
{ "Statement": [ { "Effect": "Allow", "Action": "tns:*", "Resource": "*" } ], "Version": "1" }
If your RAM user has permissions on Tunnel Service, skip this operation. For more information about how to grant permissions to a RAM user by using an Alibaba Cloud account, see Grant permissions to a RAM user by using an Alibaba Cloud account.
- Optional:Download tools related to breakpoint debugging
- If you need to use Visual Studio Code (VS Code) to implement breakpoint debugging, download and install VS Code.
- If you need to use IntelliJ IDEA to implement breakpoint debugging of Java functions, install the following tools:
Procedure
Breakpoint debugging
The following sample Python 3 code describes how to implement breakpoint debugging during interconnection between on-premises and cloud applications:
- Run the following command in the project directory to prepare helper resources and
an on-premises environment for interconnection between on-premises and cloud applications.
s proxied setup --config vscode --debug-port 3000
Sample command output:
[2021-10-08T15:55:16.653] [INFO ] [S-CLI] - Start ... Session created, session id: S-d847ae28-767f-4532-a2f2-307ee2b99c5f. [2021-10-08T15:55:18.395] [INFO ] [FC-PROXIED-INVOKE] - Deploying helper function... [2021-10-08T15:55:18.397] [INFO ] [FC-PROXIED-INVOKE] - Creating cleaner service... [2021-10-08T15:55:22.021] [INFO ] [FC-DEPLOY] - Using region: cn-hangzhou [2021-10-08T15:55:22.022] [INFO ] [FC-DEPLOY] - Using access alias: default [2021-10-08T15:55:22.022] [INFO ] [FC-DEPLOY] - Using accessKeyID: LTAI4G4cwJkK4Rza6xd9**** [2021-10-08T15:55:22.022] [INFO ] [FC-DEPLOY] - Using accessKeySecret: eCc0GxSpzfq1DVspnqqd6nmYNN**** Using fc deploy type: sdk, If you want to deploy with pulumi, you can [s cli fc-default set deploy-type pulumi] to switch. [2021-10-08T15:55:22.971] [INFO ] [FC-DEPLOY] - Checking Service SESSION-S-d847a exists [2021-10-08T15:55:23.293] [INFO ] [FC-DEPLOY] - Setting role: AliyunFCDefaultRole [2021-10-08T15:55:23.886] [INFO ] [RAM] - Checking Role AliyunFCDefaultRole exists [2021-10-08T15:55:24.099] [INFO ] [RAM] - Updating role: AliyunFCDefaultRole [2021-10-08T15:55:24.191] [INFO ] [RAM] - Checking Plicy AliyunFCDefaultRolePolicy exists [2021-10-08T15:55:24.300] [INFO ] [FC-DEPLOY] - Checking Function http-trigger-py36 exists [2021-10-08T15:55:24.577] [WARN ] [FC-DEPLOY] - Image registry.cn-hangzhou.aliyuncs.com/aliyunfc/ts-remote:v0.1.1 dose not exist locally. Maybe you need to run 's build' first if it dose not exist remotely. [2021-10-08T15:55:24.580] [INFO ] [FC-DEPLOY] - Checking Trigger httpTrigger exists [2021-10-08T15:55:24.807] [INFO ] [FC-DEPLOY] - Checking Trigger httpTrigger exists Make service SESSION-S-d847a success.// The helper service is deployed. Make function SESSION-S-d847a/http-trigger-py36 success.// The helper function is deployed. Make trigger SESSION-S-d847a/http-trigger-py36/httpTrigger success.// The helper trigger is deployed. [2021-10-08T15:55:26.129] [INFO ] [FC-DEPLOY] - Checking Service SESSION-S-d847a exists [2021-10-08T15:55:26.568] [INFO ] [FC-DEPLOY] - Checking Function http-trigger-py36 exists [2021-10-08T15:55:26.922] [INFO ] [FC-DEPLOY] - Checking Trigger httpTrigger exists [2021-10-08T15:55:27.542] [INFO ] [FC-DEPLOY] - Using customDomain: auto: fc will try to generate related custom domain resources automatically End of request Deployed. End of request [2021-10-08T15:55:35.499] [INFO ] [FC-DEPLOY] - Generated auto custom domain: http-trigger-py36.session-s-d847a.188077086902****.cn-hangzhou.fc.devsapp.net [2021-10-08T15:55:35.499] [INFO ] [FC-DEPLOY] - Creating custom domain: http-trigger-py36.session-s-d847a.188077086902****.cn-hangzhou.fc.devsapp.net [2021-10-08T15:55:35.679] [INFO ] [FC-DOMAIN] - Creating custom domain: http-trigger-py36.session-s-d847a.188077086902****.cn-hangzhou.fc.devsapp.net There is auto config in the service: SESSION-S-d847a Helper function is set to 1 provison and 0 elasticity.// The container in Function Compute (C) is started. Proxy container is running.// The code container in the on-premises environment (A) is started. Session established!// The session is established. [2021-10-08T15:56:13.251] [INFO ] [FC-PROXIED-INVOKE] - Pulling image registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-python3.6:1.9.19, you can also use 'docker pull registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-python3.6:1.9.19' to pull image by yourself. 1.9.19: Pulling from aliyunfc/runtime-python3.6 ...... Digest: sha256:6a4da97962dba5f6cb00c5e8e83024c4758ec358e5bf884efff897b9826d9454 Status: Downloaded newer image for registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-python3.6:1.9.19 [2021-10-08T15:56:15.694] [INFO ] [FC-PROXIED-INVOKE] - Checking Server in function container is up. exists FunctionCompute python3 runtime inited. FC Invoke End RequestId: unknown_request_id, Error: Unhandled function error [2021-10-08T15:56:16.831] [INFO ] [FC-PROXIED-INVOKE] - Server in function container is up!// The execution environment of Function Compute in the on-premises environment (A) is started. End of method: proxied
After the s proxied setup command is run, the project is blocked here and waits to be invoked. If you directly run the s proxied invoke command, an on-premises invocation in normal mode is implemented. If you require breakpoint debugging, insert a breakpoint (marked by ① in the figure) to the function code in the editor margin of VS Code and click the debugging icon (marked by ② in the figure).
- Open a new terminal and run the following command to invoke the function:
s proxied invoke
After you run the s proxied invoke command, you can return to VS Code. In this case, breakpoint debugging for the function has started.
- Run the following command to clear the helper resources, session, and on-premises
debugging container:
s proxied clean
The following sample Java 8 code describes how to use IntelliJ IDEA to implement breakpoint debugging:
- Run the following command in the project directory to install dependencies:
s build --use-docker
Sample command output:
[2021-10-09T15:28:39.391] [INFO ] [S-CLI] - Start ... [2021-10-09T15:28:40.520] [INFO ] [FC-BUILD] - Build artifact start... [2021-10-09T15:28:40.548] [INFO ] [FC-BUILD] - Use docker for building. [2021-10-09T15:28:40.867] [INFO ] [FC-BUILD] - Build function using image: registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-java8:build-1.9.21 [2021-10-09T15:28:41.411] [INFO ] [FC-BUILD] - begin pulling image registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-java8:build-1.9.21, you can also use docker pull registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-java8:build-1.9.21 to pull image by yourself. build-1.9.21: Pulling from aliyunfc/runtime-java8 ...... Digest: sha256:35eb46f6235729dbcb1fa48f4ce4ae7b213b967a0f1b9c625e464dbba58af22d Status: Downloaded newer image for registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-java8:build-1.9.21 [2021-10-09T15:30:52.690] [INFO ] [FC-BUILD] - Build artifact successfully. Tips for next step ====================== * Invoke Event Function: s local invoke * Invoke Http Function: s local start * Deploy Resources: s deploy End of method: build
- Run the following command to prepare helper resources and an on-premises environment
for interconnection between on-premises and cloud applications.
s proxied setup --debug-port 3000
After the s proxied setup command is run, the project is blocked here and waits to be invoked. If you directly run the s proxied invoke command, an on-premises invocation in normal mode is implemented. If you require breakpoint debugging, you must configure IntelliJ IDEA when you perform breakpoint debugging for the first time.
- Open IntelliJ IDEA, and then open the corresponding project directory. In the top navigation bar of IntelliJ IDEA, choose Run > Debug Configurations.
- In the Run/Debug Configurations dialog box, click the plus icon, select Remote, and then set the following parameters:
- Name: the name of the custom debugger.
- Port: Set the value of this parameter to 3000. If you use the
--debug-port
parameter to specify a different port when you prepare helper resources and an on-premises environment for interconnection between on-premises and cloud applications, you must set the Port parameter to the specified port.
- Click ok to complete the IntelliJ IDEA configuration.
- Insert a breakpoint (marked by ① in the figure) to the function code in the editor
margin of IntelliJ IDEA and click the debugging icon (marked by ② in the figure).
- Open a new terminal and run the following command to invoke the function:
s proxied invoke
After you run the s proxied invoke command, you can return to IntelliJ IDEA. In this case, breakpoint debugging for the function has started.
- Run the following command to clear the helper resources, session, and on-premises
debugging container:
s proxied clean