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.
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_namespecifies the name of the network connection that you established.
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
Step 2: Call the UDF to access resources in the VPC
- Start the MaxCompute client.
- 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.