CREATE GATEWAY

Creates a new gateway in the current schema. A gateway enables traffic splitting across multiple service endpoints.

See also:

ALTER GATEWAY , DESCRIBE GATEWAY, DROP GATEWAY , SHOW GATEWAYS

语法

CREATE [ OR REPLACE ] GATEWAY [ IF NOT EXISTS ] <name>
  FROM SPECIFICATION <specification_text>

必填参数

name

指定网关标识符的字符串;对于在网关中创建任务的架构,必须是唯一的。

FROM SPECIFICATION

指定内联网关规范。该规范定义了流量拆分配置。

该规范使用以下格式:

spec:
  type: traffic_split
  split_type: custom
  targets:
  - type: endpoint
    value: <db>.<schema>.<service>!<endpoint>
    weight: <weight>
  - type: endpoint
    value: <db>.<schema>.<service>!<endpoint>
    weight: <weight>

规范参数

type

Fixed value. Must be set to traffic_split.

split_type

Fixed value. Must be set to custom.

targets

要将流量路由到的目标端点列表。每个目标必须指定:

type

Fixed value. Must be set to endpoint.

value

The fully qualified endpoint name in the format db.schema.service!endpoint. Each target endpoint must exist.

weight

此端点的流量权重,指定为整数。所有权重之和必须为 100。

Note

  • 默认情况下,每个网关的最大端点数为 5。

访问控制要求

A role used to execute this operation must have the following privileges at a minimum:

权限对象备注
CREATE GATEWAY架构在架构中创建网关时需要。
BIND SERVICE ENDPOINT账户将服务端点绑定到网关时需要。
USAGE数据库对于包含网关的数据库是必需的。
USAGE架构对于包含网关的架构是必需的。
USAGE服务端点Required on the target service endpoints. Grant the service role ALL_ENDPOINTS_USAGE to provide access.

要授予所需权限,请使用以下命令:

-- Grant CREATE GATEWAY privilege in the schema
GRANT CREATE GATEWAY ON SCHEMA <schema_name> TO ROLE <role_name>;

-- Grant BIND SERVICE ENDPOINT privilege on the account
GRANT BIND SERVICE ENDPOINT ON ACCOUNT TO ROLE <role_name>;

-- Grant USAGE on target endpoints via service role
GRANT SERVICE ROLE <db_name>.<schema_name>.<service_name>!ALL_ENDPOINTS_USAGE TO ROLE <role_name>;

For instructions on creating a custom role with a specified set of privileges, see Creating custom roles.

For general information about roles and privilege grants for performing SQL actions on securable objects, see Overview of Access Control.

使用说明

  • 关于元数据:

    Attention

    Customers should ensure that no personal data (other than for a User object), sensitive data, export-controlled data, or other regulated data is entered as metadata when using the Snowflake service. For more information, see Metadata fields in Snowflake.

示例

创建在两个服务端点之间拆分流量的网关:

CREATE GATEWAY split_gateway
  FROM SPECIFICATION $$
spec:
  type: traffic_split
  split_type: custom
  targets:
  - type: endpoint
    value: db.schema.s2!ep1
    weight: 60
  - type: endpoint
    value: db.schema.s1!ep1
    weight: 40
$$;

使用新的流量拆分配置创建或替换网关:

CREATE OR REPLACE GATEWAY split_gateway
  FROM SPECIFICATION $$
spec:
  type: traffic_split
  split_type: custom
  targets:
  - type: endpoint
    value: db.schema.service1!endpoint1
    weight: 70
  - type: endpoint
    value: db.schema.service2!endpoint1
    weight: 30
$$;