All Products
Search
Document Center

MaxCompute:Access VPC resources from a UDF

Last Updated:Aug 21, 2026

By default, MaxCompute does not allow user-defined functions (UDFs) to directly access a Virtual Private Cloud (VPC). To access resources in a VPC from a UDF, you must first establish a network connection between MaxCompute and the target VPC. This topic shows how to access VPC resources from a UDF.

Prerequisites

Ensure you meet the following conditions:

Background information

To access VPC resources from a UDF, you must create a network connection between MaxCompute and the target VPC. For more information, see Create a network connection. After creating the network connection, add the set odps.session.networklink=<networklink_name>; property before the SQL statement that calls the UDF and submit them together. networklink_name is the name of the network connection that you created.

Limits

Due to region-specific limitations, you can access VPC resources from a UDF only in the following regions: China (Beijing), China (Shanghai), China (Zhangjiakou), China (Hangzhou), China (Shenzhen), China (Hong Kong), Singapore, Germany (Frankfurt), and US (Virginia).

Step 1: Create a network connection

Log on to the MaxCompute console. In the upper-left corner, select a region. In the left-side navigation pane, choose Tenants > Network Connection to create a network connection. For detailed instructions, see Create a network connection.

Step 2: Access VPC resources via UDF

  1. Install and log in to the MaxCompute client.

  2. Register the function.

    1. Download udf-3.jar.

    2. Place the downloaded JAR file in the bin directory of your local MaxCompute client installation. Then, run the following command to upload the JAR file as a resource.

      Note

      If the JAR file is in a different directory, you must include the full path in the command.

      add jar udf-3.jar;
    3. Run the following command to register the function:

      create FUNCTION  t_telnet as 'com.ali.odps.udf.Telnet' USING 'udf-3.jar';
  3. Run an SQL statement to call the UDF.

    set odps.sql.type.system.odps2=true;
    -- Specify the name of the network connection configured for the VPC. This setting is valid only for the current session.
    set odps.session.networklink=testLink;
    -- Run the SQL statement to call the UDF and access the VPC resource.
    select t_telnet("172.16.xxx.xxx",<port>,<timeout>);

    If the command returns True, the network connection is established and you can call the UDF. If an error occurs, verify your network connection configuration.