Step 4: Create the External Function for GCP in Snowflake

These instructions show how to create an external function database object in Snowflake. This database object stores information about the remote service, such as the parameters that the remote service accepts.

In this Topic:

Create the External Function Database Object

You should be in a Snowflake web interface session.

  1. Paste the command CREATE EXTERNAL FUNCTION. The command looks similar to the following:

    create or replace external function <external_function_name>(<parameters>)
        returns variant
        api_integration = <api_integration_name>
        as '<function_URL>' ;
    
  2. Replace the <external_function_name> with a unique function name (e.g. echo).

  3. Record the function name in the “External Function Name” field in the worksheet.

  4. Replace the <parameters> with the names and SQL data types of the parameters, if any. For example: a integer, b varchar.

    The parameters must correspond to the parameters expected by the remote service. The parameter names do not need to match, but the data types need to be compatible.

  5. Record the parameter name and data types in the “External Function Name” field in the worksheet.

  6. In the api_integration clause, replace the <api_integration_name> with the value in the “API Integration Name” field in the worksheet.

  7. Replace the <function_URL> with the value in the “Gateway Base URL” field in the worksheet, followed by a slash (/) and the value in the “Path Suffix” field in the worksheet.

    The URL should look similar to:

    https://<gateway-base-url>/<path-suffix>
    
  8. If you have not already done so, then execute the CREATE EXTERNAL FUNCTION command that you typed above.

  9. You should now be able to call your external function to verify that it works correctly. For details, see Calling an External Function for GCP.

Next Step

Snowflake strongly recommends setting a security policy on the Google Cloud API Gateway:

Step 5: Set the Security Policy for the Proxy Service (Google Cloud API Gateway)