CREATE SERVICE

Creates a new Snowpark Container Services service in the current schema. If a service with that name already exists, use the DROP SERVICE command to delete the previously created service.

You can run more than one instance of your service. Each service instance is a collection of containers, as defined in the service specification file, that run together on a node in your compute pool. If you run multiple instances of a service, a load balancer manages incoming traffic.

Note that the command parameters must be specified in specific order. For more information, see the Usage Notes section.

See also:

ALTER SERVICE , DESCRIBE SERVICE, DROP SERVICE , SHOW SERVICES

Syntax

CREATE SERVICE [ IF NOT EXISTS ] <name>
  IN COMPUTE POOL <compute_pool_name>
  {
     fromSpecification
     | fromSpecificationTemplate
  }
  [ EXTERNAL_ACCESS_INTEGRATIONS = ( <EAI_name> [ , ... ] ) ]
  [ AUTO_RESUME = { TRUE | FALSE } ]
  [ MIN_INSTANCES = <num> ]
  [ MAX_INSTANCES = <num> ]
  [ QUERY_WAREHOUSE = <warehouse_name> ]
  [ [ WITH ] TAG ( <tag_name> = '<tag_value>' [ , <tag_name> = '<tag_value>' , ... ] ) ]
  [ COMMENT = '{string_literal}']
Copy

Where:

fromSpecification ::=
  {
    FROM @<stage> SPECIFICATION_FILE = '<yaml_file_stage_path>'
    | FROM SPECIFICATION <specification_text>
  }
Copy
fromSpecificationTemplate ::=
  {
    FROM @<stage> SPECIFICATION_TEMPLATE_FILE = '<yaml_file_stage_path>'
    | FROM SPECIFICATION_TEMPLATE <specification_text>
  }
  USING ( <key> => <value> [ , <key> => <value> [ , ... ] ]  )
Copy

Required parameters

name

String that specifies the identifier (that is, the name) for the service; it must be unique for the schema in which the service is created.

Quoted names for special characters or case-sensitive names are not supported. The same constraint also applies to database and schema names where you create a service. That is, database and schema names without quotes are valid when creating a service.

IN COMPUTE POOL compute_pool_name

Specifies the name of the compute pool in your account on which to run the service.

FROM stage

Specifies the Snowflake internal stage where the specification file is stored; for example, @tutorial_stage.

SPECIFICATION_FILE = 'yaml_file_stage_path'

Specifies the path to the service specification file on the stage; for example, 'some-dir/echo_spec.yaml'.

SPECIFICATION_TEMPLATE_FILE = 'yaml_file_stage_path'

Specifies the path to the service specification template file on the stage; for example, 'some-dir/echo_template_spec.yaml'. When SPECIFICATION_TEMPLATE_FILE is specified, the USING parameter is required.

FROM SPECIFICATION specification_text

Specifies service specification. You can use a pair of dollar signs ($$) to delimit the beginning and ending of the specification string.

FROM SPECIFICATION_TEMPLATE specification_text

Specifies service specification. You can use a pair of dollar signs ($$) to delimit the beginning and ending of the specification string. When SPECIFICATION_TEMPLATE is specified, the USING parameter is required.

Optional parameters

EXTERNAL_ACCESS_INTEGRATIONS = ( EAI_name [ , ... ] )

Specifies the names of the external access integrations that allow your service to access external sites. The names in this list are case-sensitive. By default, application containers don’t have permission to access the internet. If you want to allow your service to access an external site, create an External Access Integration (EAI), and configure your service to use that integration. For more information, see Network egress.

AUTO_RESUME = { TRUE | FALSE }

Specifies whether to automatically resume a service when a service function or ingress is called.

  • If AUTO_RESUME is FALSE, you need to explicitly resume the service (using ALTER SERVICE … RESUME).

  • If AUTO_RESUME is TRUE, Snowflake resumes the suspended service when a service function is called or when a request is received (ingress).

MIN_INSTANCES = num

Specifies the minimum number of service instances to run.

Default: 1.

MAX_INSTANCES = num

Specifies the maximum number of service instances to run.

QUERY_WAREHOUSE = warehouse_name

Warehouse to use if a service container connects to Snowflake to execute a query but does not explicitly specify a warehouse to use.

Default: none.

TAG ( tag_name = 'tag_value' [ , tag_name = 'tag_value' , ... ] )

Specifies the tag name and the tag string value.

The tag value is always a string, and the maximum number of characters for the tag value is 256.

For information about specifying tags in a statement, see Tag quotas for objects and columns.

COMMENT = 'string_literal'

Specifies a comment for the service.

Default: No value

USING ( key => value [ , key => value [ , ... ] ]  )

Lets you provide values to parameterize specification template expansion.

USING is required when using a specification template (FROM SPECIFICATION_TEMPLATE_FILE or FROM SPECIFICATION_TEMPLATE). The key-value pairs must form a comma-separated list.

Where:

  • key is the name of the template variable. The template variable name can optionally be enclosed in double quotes (").

  • value is the value to assign to the variable in the template. String values must be enclosed in ' or $$. The value must either be alphanumeric or valid JSON.

Access control requirements

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

Privilege

Object

Notes

CREATE SERVICE

Schema

USAGE

Compute pool

READ

Stage

This is the stage where the specification is stored.

READ

Image repository

Repository of images referenced by the specification.

BIND SERVICE ENDPOINT

Account

A role must have this privilege to create a service with public endpoints. This allows the service access through the public endpoints. If the service’s owner role loses this privilege, the public endpoints will not be accessible.

Note that operating on any object in a schema also requires the USAGE privilege on the parent database and schema.

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.

Usage notes

  • When calling CREATE SERVICE, the parameters should be provided in this order: specify compute pool, followed by the service specification (either provider specification file on stage or inline specification), and then other properties.

  • Regarding metadata:

    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.

Examples

Create a service with two service instances running:

CREATE SERVICE echo_service
  IN COMPUTE POOL tutorial_compute_pool
  FROM @tutorial_stage
  SPECIFICATION_FILE='echo_spec.yaml'
  MIN_INSTANCES=2
  MAX_INSTANCES=2
Copy