Step 2: Create the Proxy Service (Google Cloud API Gateway) in the Console¶
Snowflake does not send data (HTTP POST requests) directly to a remote service. Instead, Snowflake sends the data to a proxy service that relays the data from Snowflake to the remote service (i.e. GCP Cloud Function) and back again.
This topic provides instructions for creating and configuring a Google Cloud API Gateway for use as the proxy service for your external function.
In this Topic:
Create an API Definition¶
On your local file system, create and customize a YAML-formatted configuration file that specifies the API you are creating. The file
should have the
Configuration file template:
swagger: '2.0' info: title: API Gateway config for Snowflake external function. description: This configuration file connects the API Gateway resource to the remote service (Cloud Function). version: 1.0.0 schemes: - https produces: - application/json paths: /<PATH>: post: summary: Echo the input. operationId: echo x-google-backend: address: <HTTP ENDPOINT TO ROUTE REQUEST TO> protocol: h2 responses: '200': description: <DESCRIPTION> schema: type: string
Fill in or update the following fields:
<PATH>with a unique name. This will be incorporated into URLs, so use only characters that are valid in URLs. For example, enter
Note that, unlike the other fields in this configuration file, enter the
<PATH>value before the colon, rather than after the colon. For example, the following is correct:
The path name should not contain any path parameters. Google supports path parameters when setting the path to a URL. However, Snowflake does not support path parameters in the corresponding URL specified in the CREATE EXTERNAL FUNCTION statement.
Copy the path (e.g.
demo-func-resource) from the immediately preceding step to the “Path Suffix” field in your tracking worksheet.
addressfield under the
x-google-backendfield, and replace
<HTTP ENDPOINT TO ROUTE REQUEST TO>with the value from the “Cloud Function Trigger URL” field in your tracking worksheet. The result should look similar to:
x-google-backend: address: https:// ...
The URL should not be enclosed in quotation marks.
The URL does not need to be an endpoint hosted by Google; it can be the path to any HTTP endpoint.
If you selected Require HTTPS in Step 1: Create the Remote Service (Google Cloud Function) in the Console, then ensure that the URL you enter into the
addressfield starts with
Optionally, you can update any of the following values:
postsubsection of the
postsubsection of the
Review your sample configuration file. It should look similar to the following:
swagger: '2.0' info: title: "API Gateway config for Snowflake external function" description: "This configuration file connects the API Gateway resource to the remote service (Cloud Function)." version: 1.0.0 schemes: - https produces: - application/json paths: /demo-func-resource: post: summary: "echo the input" operationId: echo x-google-backend: address: https://my_dev.cloudfunctions.net/demo-cloud-function-01 protocol: h2 responses: '200': description: echo result schema: type: string
Save the configuration file.
Record the file path and name in the “Configuration File Name” field in your tracking worksheet.
To learn more about the API configuration file, see the following GCP documentation:
Create an API Gateway¶
To create an API Gateway:
Create a GCP API.
Create an API Config.
Create a Gateway with the API Config.
Create a GCP API¶
This step creates a GCP API, which is a container that can contain one or more API Gateways and one or more configuration files:
If you have not already done so, go to the Google Cloud API Gateway screen by clicking on the GCP menu and selecting API Gateway.
Click on CREATE GATEWAY.
Enter the Display Name and the API ID (e.g.
You do not need to record these values in your tracking worksheet because you do not need to enter these later to create your external function. However, you might want to record the API ID so that you can delete it when you are done with it.
Create an API Config¶
Upload your configuration file to the console, which creates an API Config.
Scroll to the API Config section of the screen.
Search for the field that contains Upload an API Spec.
Click on BROWSE and select your configuration file. The name of your configuration file was recorded in the “Configuration File Name” field in your tracking worksheet.
Enter a display name into the field that contains Display Name.
Select a service account.
If you created the sample function, then in the field that contains Select a Service Account, select App Engine default service account.
If you are creating a function to use in production (rather than as a sample), you might choose a different service account.
The selected service account must have appropriate privileges, including privileges to call the Cloud Function.
Create a Gateway with the API Config¶
Scroll to the Gateway details section of the screen.
Enter the Display Name of the new API Gateway.
Click in the Location field and select the appropriate region (e.g.
Click on CREATE GATEWAY.
This takes you to the APIs screen and shows you a list of your APIs.
If your new API is not visible immediately, wait a few minutes, then click the Refresh button.
Copy the value of the API’s Managed Service to the “Managed Service Identifier” field in your tracking worksheet.
At this point, you should still see a list of your APIs. Click on the name of the API.
You should see 4 tabs: OVERVIEW, DETAILS, CONFIGS, and GATEWAYS.
Click on the GATEWAYS tab.
Copy the Gateway URL to the “Gateway Base URL” field in your tracking worksheet.