Snow 应用程序运行

在 Snowflake 账户中创建应用程序包,将代码文件上传到相应暂存区,然后通过应用程序包创建或升级应用程序对象。

语法

snow app run
  --version <version>
  --patch <patch>
  --from-release-directive
  --channel <channel>
  --interactive / --no-interactive
  --force
  --validate / --no-validate
  --package-entity-id <package_entity_id>
  --app-entity-id <app_entity_id>
  --project <project_definition>
  --env <env_overrides>
  --connection <connection>
  --host <host>
  --port <port>
  --account <account>
  --user <user>
  --password <password>
  --authenticator <authenticator>
  --workload-identity-provider <workload_identity_provider>
  --private-key-file <private_key_file>
  --token <token>
  --token-file-path <token_file_path>
  --database <database>
  --schema <schema>
  --role <role>
  --warehouse <warehouse>
  --temporary-connection
  --mfa-passcode <mfa_passcode>
  --enable-diag
  --diag-log-path <diag_log_path>
  --diag-allowlist-path <diag_allowlist_path>
  --oauth-client-id <oauth_client_id>
  --oauth-client-secret <oauth_client_secret>
  --oauth-authorization-url <oauth_authorization_url>
  --oauth-token-request-url <oauth_token_request_url>
  --oauth-redirect-uri <oauth_redirect_uri>
  --oauth-scope <oauth_scope>
  --oauth-disable-pkce
  --oauth-enable-refresh-tokens
  --oauth-enable-single-use-refresh-tokens
  --client-store-temporary-credential
  --format <format>
  --verbose
  --debug
  --silent
  --enhanced-exit-codes
  --decimal-precision <decimal_precision>

实参

选项

--version TEXT

您要用来创建应用程序对象的现有应用程序包定义版本。根据项目定义文件确定应用程序对象和应用程序包名称。

--patch INTEGER

The patch number under the given –version defined in an existing application package that should be used to create an application object. The application object and application package names are determined from the project definition file.

--from-release-directive

创建或升级应用程序对象,使其适用于 Snowflake 账户的版本指令指定的版本和补丁。如果给定应用程序包的 Snowflake 账户不存在版本指令,则该命令将失败,指令会由项目定义文件确定。默认:未设置。默认值:False。

--channel TEXT

The name of the release channel to use when creating or upgrading an application instance from a release directive. Requires the –from-release-directive flag to be set. If unset, the default channel will be used.

--interactive / --no-interactive

启用此选项后,即使标准输入和输出不是终端设备,也会显示提示。在交互式 shell 环境中默认值为 True,否则为 False。

--force

启用此选项后,命令会隐式批准出现的任何提示。如果未指定交互模式,并且想要执行可能具有破坏性的操作,则应启用此选项。默认为未设置。默认值:False。

--validate / --no-validate

启用后,此选项将触发已部署的 Snowflake Native App 安装脚本 SQL 的验证。默认值:True。

--package-entity-id TEXT

当 definition_version 为 2 或更高时,要操作的包实体的 ID。

--app-entity-id TEXT

当 definition_version 为 2 或更高时,要操作的应用程序实体的 ID。

-p, --project TEXT

Snowflake 项目的存储路径。默认为当前工作目录。

--env TEXT

格式为 key=value 的字符串。替换用于模板的 env 部分的变量。默认值:[]。

--connection, -c, --environment TEXT

Name of the connection, as defined in your config.toml file. Default: default.

--host TEXT

连接的主机地址。替换为连接指定的值。

--port INTEGER

连接的端口。替换为连接指定的值。

--account, --accountname TEXT

分配给 Snowflake 账户的名称。替换为连接指定的值。

--user, --username TEXT

连接到 Snowflake 的用户名。替换为连接指定的值。

--password TEXT

Snowflake 密码。替换为连接指定的值。

--authenticator TEXT

Snowflake 身份验证器。替换为连接指定的值。

--workload-identity-provider TEXT

工作负载身份提供商(AWS、AZURE、GCP、OIDC)。替换为连接指定的值。

--private-key-file, --private-key-path TEXT

Snowflake 私钥文件路径。替换为连接指定的值。

--token TEXT

连接到 Snowflake 时使用的 OAuth 令牌。

--token-file-path TEXT

连接到 Snowflake 时使用的带有 OAuth 令牌的文件路径。

--database, --dbname TEXT

要使用的数据库。替换为连接指定的值。

--schema, --schemaname TEXT

要使用的数据库架构。替换为连接指定的值。

--role, --rolename TEXT

要使用的角色。替换为连接指定的值。

--warehouse TEXT

要使用的仓库。替换为连接指定的值。

--temporary-connection, -x

Uses a connection defined with command-line parameters, instead of one defined in config. Default: False.

--mfa-passcode TEXT

用于多重身份验证的令牌 (MFA)。

--enable-diag

是否生成连接诊断报告。默认值:False。

--diag-log-path TEXT

Path for the generated report. Defaults to system temporary directory. Default: <system_temporary_directory>.

--diag-allowlist-path TEXT

包含允许列表参数的 JSON 文件的路径。

--oauth-client-id TEXT

身份提供商为 Snowflake 集成提供的客户端 ID 的值。

--oauth-client-secret TEXT

身份提供商为 Snowflake 集成提供的客户端密钥的值。

--oauth-authorization-url TEXT

向驱动程序提供授权码的身份提供商端点。

--oauth-token-request-url TEXT

向驱动程序提供访问令牌的身份提供商端点。

--oauth-redirect-uri TEXT

URI 用于授权码重定向。

--oauth-scope TEXT

身份提供商授权请求中请求的范围。

--oauth-disable-pkce

Disables Proof Key for Code Exchange (PKCE). Default: False.

--oauth-enable-refresh-tokens

Enables a silent re-authentication when the actual access token becomes outdated. Default: False.

--oauth-enable-single-use-refresh-tokens

Whether to opt-in to single-use refresh token semantics. Default: False.

--client-store-temporary-credential

存储临时凭据。

--format [TABLE%JSON%JSON_EXT|CSV]

指定输出格式。默认:TABLE。

--verbose, -v

Displays log entries for log levels info and higher. Default: False.

--debug

Displays log entries for log levels debug and higher; debug logs contain additional information. Default: False.

--silent

关闭到控制台的中间输出。默认值:False。

--enhanced-exit-codes

根据错误类型区分退出错误代码。默认值:False。

--decimal-precision INTEGER

Number of decimal places to display for decimal values. Uses Python’s default precision if not specified. [env var: SNOWFLAKE_DECIMAL_PRECISION].

--help

Displays the help text for this command.

使用说明

Note

This command does not accept a role or warehouse overrides to your config.toml file. Please add them to the native app definition in the snowflake.yml or snowflake.local.yml instead.

This command relies on the resolved project definition to determine the stage to which to upload files, which files to upload, and the name of the objects to create. For guidance on defaults, please refer to About Snowflake Native App projects and snow init usage notes. You can also change them to be according to your own preference, though it is your responsibility to check if there is any clash with existing objects in your account.

By default, the snow app run command creates an application package in your Snowflake account, uploads code files to its stage, validates the setup script SQL, and then creates (or upgrades) a development-mode instance of that application. You should keep the following in mind when running the default command:

  • All files specified under nativeapp.project.artifacts in the project definition file(s) are uploaded to the Snowflake stage. This artifact must include a manifest.yml file and its related setup script(s).
  • All files specified under nativeapp.project.artifacts must have already been compiled and packaged separately, if needed, before calling snow app run. Snowflake CLI does not offer any feature to perform these intermediate tasks for you, so you have full control over your build process by executing it in your own scripts.
  • Snowflake CLI uses default application package name, stage name, and application name when creating those objects.
  • Subsequent runs of snow app run after the initial one compare the state of your uploaded files to the files in your local directory, and selectively upload only the modified files to save you time. If any files have changed, the application is upgraded based on the new contents of the stage.
  • If the application package already exists and its distribution property is INTERNAL, the command checks if the package was created by the Snowflake CLI. If it was not, the command throws an error. If the distribution of the application package is EXTERNAL, no such check is performed.
  • 如果您正在使用的应用程序包的分发值与解析的项目定义中设置的值不同,则该命令会警告您,但会继续执行。
  • The application instance is created or upgraded in development mode. Specifically, it uses the staged files.

If you specify a --version, --patch or --from-release-directive option, this command upgrades your existing application instance, or creates one if the application does not exist. It does not create an application package in this scenario.

  • If Snowflake CLI is not able to update your application for any reason, such as trying to upgrade an application initially installed in loose files mode to use release directives instead, it attempts to drop the existing application and create a new one using the desired installation strategy. The command prompts you to confirm the drop before performing the action.
  • If you do not want to interact with the command and instead force all actions, use the --force option to bypass all prompts, which proxies as a yes to all the inputs asking whether to proceed with destructive actions.
  • Snowflake CLI tries to determine if you are running the commands in an interactive shell. If --force is not provided and you are executing commands in the interactive shell, it automatically chooses the interactive option for you.
  • If you want to force Snowflake CLI to interact with you even if not in an interactive shell, use the --interactive option.

示例

These examples assume you have made the necessary changes to your code files and added them to your snowflake.yml or snowflake.local.yml files.

  • 如果要使用暂存文件创建应用程序包和应用程序,可以执行以下操作:

    cd my_app_project
    my_app_project_build_script.sh
    snow app run --connection="dev"
  • 如果您已经拥有带有版本和修补程序的应用程序包,希望使用此版本和补丁创建应用程序,并调用交互模式,则可以执行以下操作:

    snow app run --version V1 --patch 12 --interactive --connection="dev"

    Here, version V1 and patch 12 are used as an example only.

  • 如果您在应用程序包设置了现有的版本指令,希望使用其创建应用程序并绕过交互模式,则可以执行以下操作:

    snow app run --from-release-directive --force --connection="dev"
  • 要从非默认发布通道的发布指令创建应用程序,请执行:

    snow app run --from-release-directive --channel ALPHA --connection="dev"
  • This example shows how to pass in multiple environment variables using the --env option:

    snow app run --env source_folder="src/app" --env stage_name=mystage