All Products
Search
Document Center

MaxCompute:Use UDFs to access resources in VPCs

Last Updated:Mar 25, 2026

By default, MaxCompute blocks user-defined function (UDF) access to resources inside virtual private clouds (VPCs). To enable this, establish a network connection between MaxCompute and the target VPC, then pass the connection name as a session parameter when you run the UDF.

Prerequisites

Before you begin, make sure you have:

Supported regions

The VPC connection scheme is supported only in the following regions. UDFs can access VPC resources only in these regions.

  • China (Beijing)

  • China (Shanghai)

  • China (Zhangjiakou)

  • China (Hangzhou)

  • China (Shenzhen)

  • China (Hong Kong)

  • Singapore

  • Germany (Frankfurt)

  • US (Virginia)

If your VPC is in a region not listed above, UDF-based VPC access is not available.

How it works

  1. Establish a network connection between MaxCompute and your VPC in the MaxCompute console.

  2. Download and register the telnet UDF (udf-3.jar) to test connectivity.

  3. Run a SQL statement with set odps.session.networklink=<networklink_name> to bind the connection, then call the UDF.

The session parameter is valid only for the current session and must be committed together with the SQL statement.

Step 1: Establish a network connection

Log in to the MaxCompute console. In the upper-left corner, select the target region. In the left navigation pane, go to Tenants > Network Connection and create a network connection to your VPC.

For detailed steps, see Access over a VPC (dedicated connection).

Step 2: Call the UDF to access VPC resources

2.1 Install and start the MaxCompute client

Install and start the MaxCompute client.

2.2 Register the UDF

  1. Download udf-3.jar.

  2. Place the JAR file in the bin directory of your local MaxCompute client installation, then upload it as a resource:

    If the JAR file is in a different directory, include the full path in the command.
    add jar udf-3.jar;
  3. Register the UDF:

    create FUNCTION t_telnet as 'com.ali.odps.udf.Telnet' USING 'udf-3.jar';

2.3 Run a SQL statement to call the UDF

Run the following SQL to verify connectivity. Replace testLink with the name of the network connection you created in Step 1, and replace the placeholders with the actual IP address, port number, and timeout value of your VPC resource.

set odps.sql.type.system.odps2=true;
-- Specify the network connection name. This setting applies to the current session only.
set odps.session.networklink=testLink;
-- Call the UDF to test connectivity to the VPC resource.
select t_telnet("172.16.xxx.xxx", <Port number>, <Timeout period>);

Expected result: If the connection is established, the UDF returns True. If an error is returned, check whether the network connection information is correctly configured.

Troubleshooting

The UDF returns an error instead of `True`

Check that the network connection name in odps.session.networklink exactly matches the name configured in the MaxCompute console under Tenants > Network Connection.

The SET command has no effect

The set odps.session.networklink command must be submitted in the same session commit as the SQL statement that calls the UDF.

The connection times out

Verify that the IP address and port of the target resource are correct and that the resource is reachable from within the VPC. Also confirm that the network connection is correctly configured in the MaxCompute console.

What's next