EXECUTE JOB SERVICE

statementsupportedContainer services & dev tooling

docs.snowflake.com ↗

Note This operation is not currently covered by the Service Level set forth in Snowflake’s Support Policy and Service Level Agreement. Executes a Snowpark Container Services service as a job. A service, created using CREATE SERVICE, is long-running and you must explicitly stop it when it is no longer needed. On the other hand, a job, created using EXECUTE JOB SERVICE, is a service that terminates when your code exits, similar to a stored procedure. When all containers exit, the job is done. By default, the job runs synchronously; the EXECUTE JOB SERVICE command finishes only after all containers exit. Alternatively, you can run the job service asynchronously by specifying the optional ASYNC parameter. In this case, the command returns immediately while the job is running. You can use the DESCRIBE SERVICE command to poll for job completion and then call the SYSTEM$WAIT_FOR_SERVICES function to wait for the job to complete. After a job service completes, Snowflake automatically cleans up the resources allocated to the job service to help reduce costs. You can still access job metadata for up to 30 days by using the DESCRIBE SERVICE and SHOW SERVICES commands. After 30 days, Snowflake automatically deletes the job. When the job is done, if no other jobs or services are running on that compute pool node, Snowflake might consider the node is idle and reclaim it. When that happens, SYSTEM$GET_SERVICE_LOGS will not return local container logs from the job containers. You might consider persisting the container logs to an event table. For more information, see Publishing and accessing container logs. Note that the command parameters must be specified in a specific order. For more information, see Usage Notes. Snowpark Container Services is available to accounts in AWS, Microsoft Azure, and Google Cloud Platform commercial regions, with some exceptions. For more information, see Available regions and considerations.

Syntax

supportedpartialnot supportednot scored

EXECUTE JOB SERVICE
  IN COMPUTE POOL <compute_pool_name>
  {
     fromSpecification
     | fromSpecificationTemplate
  }
  [ NAME = [<db>.<schema>.]<name> ]
  [ ASYNC = { TRUE | FALSE } ]
  [ REPLICAS = = <num> ]
  [ QUERY_WAREHOUSE = <warehouse_name> ]
  [ COMMENT = '<string_literal>']
  [ EXTERNAL_ACCESS_INTEGRATIONS = ( <EAI_name> [ , ... ] ) ]

Where

fromSpecification ::=
  {
    FROM @<stage> SPECIFICATION_FILE = '<yaml_file_stage_path>'
    | FROM SPECIFICATION <specification_text>
  }

Where

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

Parameters

NameRequiredDescription
IN COMPUTE POOL compute_pool_namerequiredSpecifies the name of the compute pool in your account on which to run the service.
FROM stagerequiredSpecifies the Snowflake internal stage where the specification file is stored; for example, @tutorial_stage.
SPECIFICATION_FILE = 'yaml_file_stage_path'requiredSpecifies the path to the service specification file on the stage; for example, 'some-dir/echo_spec.yaml'.
SPECIFICATION_TEMPLATE_FILE = 'yaml_file_stage_path'requiredSpecifies 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_textrequiredSpecifies service specification. You can use a pair of dollar signs ($$) to delimit the beginning and ending of the specification string.
FROM SPECIFICATION_TEMPLATE specification_textrequiredSpecifies 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.
NAME = [db.schema.]nameoptionalThe name (that is the identifier) for the service, that executes like a job; 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. Default: If not specified, Snowflake generates a name for the service in a format JOB_<query_job_uuid>.
ASYNC = { TRUE | FALSE }optionalSpecifies whether to execute the job asynchronously. Default: FALSE
REPLICAS = numoptionalSpecifies the number of job replicas to run. For more information, see Run multiple replicas of a job service (batch jobs). Default: 1.
QUERY_WAREHOUSE = warehouse_nameoptionalWarehouse to use if a service container connects to Snowflake to execute a query but does not explicitly specify a warehouse to use. This parameter also supports object references in Native Apps. For more information, see Request references and object-level privileges from consumers. Default: none.
EXTERNAL_ACCESS_INTEGRATIONS = ( EAI_name [ , ... ] )optionalSpecifies the names of the external access integrations that allow your job 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 job to access an external site, create an External Access Integration (EAI), and configure your job to use that integration. For more information, see Configure service egress.
COMMENT = 'string_literal'optionalSpecifies a comment for the service. Default: No value
TAG ( tag_name = 'tag_value' [ , tag_name = 'tag_value' , ... ] )optionalSpecifies 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.
USING ( key => value [ , key => value [ , ... ] ] )optionalLets 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.

Usage notes

Access control requirements

A role used to execute this operation 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. Operating on an object in a schema requires at least one privilege on the parent database and at least one privilege on the parent 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.

See also

Referenced by