By default, MaxCompute does not allow you to access resources in virtual private clouds (VPCs) by using user-defined functions (UDFs). To use UDFs to access resources in a VPC, you must establish a network connection between MaxCompute and the VPC. This topic describes how to use a UDF to access resources in a VPC.

Prerequisites

Make sure that the following requirements are met:

Background information

Before you can use a UDF to access resources in a VPC, you must establish a network connection between MaxCompute and the VPC. For more information, see VPC connection scheme. After you establish the network connection, add set odps.session.networklink=<networklink_name>; before the SQL statement that you want to execute. Then, commit the SET command together with the SQL statement to call the UDF. networklink_name specifies the name of the network connection that you established.

Limits

The VPC connection scheme is supported only in the China (Beijing), China (Shanghai), China (Zhangjiakou), China (Hangzhou), and China (Shenzhen) regions. Therefore, you can use UDFs to access only the resources that are deployed in VPCs in these regions.

Step 1: Establish a network connection

Log on to the MaxCompute console and establish a network connection between MaxCompute and a VPC. For more information, see VPC connection scheme.

Step 2: Call the UDF to access resources in the VPC

  1. Start the MaxCompute client.
  2. Execute the SQL statement to call the UDF.
    In this example, a UDF named my_ping is created. The my_ping UDF is used to determine whether an IP address can be pinged. Sample statements:
    -- Configure the name of the network connection that you established based on the VPC connection scheme. This setting is valid only for the current session. 
    set odps.session.networklink=testLink;
    -- Execute the following SQL statement to call the UDF to access resources in the VPC: 
    select my_ping('123.56.xxx.xxx');

    If True is returned, the network connection is established and the UDF can be called. If an error is returned, check whether the network connection information is correctly configured.